Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is it possible the mdi parent form to be unmovable at runtime?

Status
Not open for further replies.

assimang

Programmer
Mar 11, 2008
96
Hello everybody.
I am new in vb 2005. I have a mdi application. Is it possible the mdi parent form to be unmovable at runtime? And how can i do this? It's my central form in my application so i don't want set the formborderstyle to none. Any help will be much appreciated.

Thanks in advanced.
 
Here's a link to a site with code to do this:




I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Thanks jebenson, this code doesn't do exactly what i want. The problem is that this class creates a new unmovable form, i am not experienced about classes and the what i want to do, is just set an existing mdi parent form unmovable at runtime. Any help will be much appreciated.

Thanks again
in advanced
 
How about something like:

Code:
Public Class Form1

	Private TopOfForm As Integer
	Private LeftOfForm As Integer

	Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
		TopOfForm = Me.Top
		LeftOfForm = Me.Left
	End Sub

	Private Sub Form1_Move(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Move
		Me.Top = TopOfForm
		Me.Left = LeftOfForm
	End Sub
End Class

In other words record the top/left of the form as soon as it as loaded and reset it to that location if the user tries to move it.

The user should not see any partial movement.


Hope this helps

[vampire][bat]
 
Out of curiosity, why not allow the users to move the form? Seems to go against standard Windows usability expectations.
 
A slight improvement:

Replace:

Code:
    Private Sub Form1_Move(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Move
        Me.Top = TopOfForm
        Me.Left = LeftOfForm
    End Sub

with:

Code:
	Private Sub Form1_Move(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Move
		If Me.Visible Then
			Me.Top = TopOfForm
			Me.Left = LeftOfForm
		End If
	End Sub

This allows the form to be positioned initially (as determined by the StartPosition property)


Hope this helps.

[vampire][bat]
 
earthandfire, you're right, and I don't know about you, but sometimes I get wedged into my programmer's mindset and really need that outside advice.
 
RiverGuy, based on some of the requests I've seen on TT, there are a lot of programs out there that will never gain access to my machine!

[vampire][bat]
 
Thanks all of you.
Earthandfire, i don't think its a good idea because the user can see form's breadcrumb while he is moving it.
The reason i wanna do this, is that i want the central mdi parent form behaves like for example microsoft internet explorer, microsoft word and not like a simple window. If you open microsoft word or internet explorer you could see that you can't move it.
I want what exactly does jebenson's code but in an existing mdi parent form. I want to be able to apply this class to an existing mdi parent form and not create an new unmovable form.

Thanks all.
 
You can move the Word and Internet Explorer windows. Are you sure that you just don't want your form maximized? When the form is maximized, you can't move it -- you have to restore down to move it. And Word and IE probably are launched maximized by default on your computer. If this is what you are looking for, then just set the WindowState property of your form to Maximized.
 
If that is what you meant, then you might want to consider adding:

[tt] If Me.WindowState <> FormWindowState.Minimized Then Me.WindowState = FormWindowState.Maximized
[/tt]

to the FormResize event handler.

[vampire][bat]
 
You might also set the form so it is centered on the screen, and to set the form so it is TopMost to true. Also disable the minimize and maximize buttons.

The above would really keep your form on the scrren, make it difficult for your users to get to or use other programs (esp. if your main form was maximized).

Don't really understand why you want to do it, but it can be done.
 
Sorry guys, i missed to refer that the mdi parent form i want it always to be maximized. Is there a way doing this?

Thanks all
 
Did you try e&f's solution?

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Yes i do harley. This is not what i want. I have a mdi parent form maximized with control box set to false, i have disabled the possibility of maximize the form. I followed e&f's code has posted in the threat how disable scrollbars in mdi parent form for this. But the user has the possibility to move the form at runtime and i don't want this. I want the mdi parent form to be unmovable as for example internet explorer, microsoft word, excel etc as i explained before. I don't want a solution that the user can't move the mdi parent form so that can see it's breadcrumb. It's a mdi parent form, its a mdi container form. Hope it helps.

Thanks all
in advanced.
 
What you are saying makes no sense. A maximized form, by its very nature cannot be moved.

If you are talking about a window within the parent form, then apply my suggestions to the child form.

[vampire][bat]
 
Surely e&f's code keeps the form maximized, therefore stopping the user moving the form? At least that is how it works for me.

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
assimang,

You must be using VERY different versions of the programs you mentioned (Internet Explorer, Word, Excel) than any I have ever seen. Because in those programs one CAN minimize the parent form, make it less that full screen and move it, etc. In Excel one can do this with both the parent and child forms.

Can you maybe post some screenshots detailing the behavior you expect from your program? As it is, I have no idea what you really want.



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top