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 derfloh 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
Joined
Mar 11, 2008
Messages
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.
 
e&f when you have a mdi parent form, and in load event you set Me.WindowState = FormWindowState.Maximized and maximizebox to true when you run the program really the form can't be moved. But if you set maximizebox to false as i want Me.WindowState = FormWindowState.Maximized in form load event you can see that the form can be moved. The what exactly i want to do, is to avoid user to maximize or restore the form either by maxbutton either dubleclicking the title bar because i want the mdi parent form always maximized. So I followed your instructions :
Set the following properties for the MdiParent:

FormBorderStyle = FixedSingle (or Fixed3D whichever you prefer)
StartPosition = CenterScreen
MinimizeBox = False
MaximizeBox = False

WindowState = Normal (default setting doesn't need to be changed)

Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()

' Add any initialization after the InitializeComponent() call.

MinimumSize = New Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height)
Dim mdi As New MdiClientWithoutScrollBars(Me)

End Sub

And the problem with this is that the mdi parent form can be moved.
So I want user can’t maximize or restore the form either by maxbutton either dubleclicking the title bar and I want the mdi parent form to be unmovable at runtime too.
 
WindowState DOES need to be changed.

WindowState = FormWindowState.Maximized

[vampire][bat]
 
So when you put e&f's code into the form's Resize event it didn't disaply the behaviour you want?

Is it that you can see the form shrink and then re-maximize that's the problem?

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.
 
well i have this class by e&f:

Imports System
Imports System.Drawing
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Windows.Forms
Imports System.Runtime.InteropServices

Public Class MdiClientWithoutScrollBars
Inherits NativeWindow
Implements IComponent
Implements IDisposable

Private FParentForm As Form
Private FMdiClient As MdiClient
Private FSite As ISite

Private Const WFNCCALCSIZE As Integer = 131
Private Const SB_BOTH As Integer = 3

<DllImport("user32.dll")> _
Private Shared Function ShowScrollBar(ByVal hWnd As IntPtr, ByVal wBar As Integer, ByVal bShow As Integer) As Integer
End Function

Public Sub New(ByVal TheParentForm As Form)
FSite = Nothing
FParentForm = TheParentForm
FMdiClient = Nothing
If Not FParentForm.IsMdiContainer Then FParentForm.IsMdiContainer = True
For a As Integer = 0 To FParentForm.Controls.Count - 1
FMdiClient = TryCast(FParentForm.Controls(a), MdiClient)
If FMdiClient IsNot Nothing Then
ReleaseHandle()
AssignHandle(FMdiClient.Handle)
Exit For
End If
Next
End Sub

Public Event Disposed As EventHandler Implements IComponent.Disposed

Public Property Site() As ISite Implements IComponent.Site
Get
Return FSite
End Get
Set(ByVal value As ISite)
FSite = value
If FSite Is Nothing Then
Return
End If
End Set
End Property

Public Sub Dispose() Implements IComponent.Dispose
Dispose(True)
GC.SuppressFinalize(Me)
End Sub

Protected Overridable Sub Dispose(ByVal disposing As Boolean)
If disposing Then
SyncLock Me
If FSite IsNot Nothing AndAlso FSite.Container IsNot Nothing Then
FSite.Container.Remove(Me)
End If
RaiseEvent Disposed(Me, EventArgs.Empty)
End SyncLock
End If
End Sub

Protected Overloads Overrides Sub WndProc(ByRef m As Message)
If m.Msg = WFNCCALCSIZE Then
ShowScrollBar(m.HWnd, SB_BOTH, 0)
End If
MyBase.WndProc(m)
End Sub


End Class


E&F what do you mean "WindowState DOES need to be changed.

WindowState = FormWindowState.Maximized "?


My problem harley is that my form is maximized but the user can move it and i don't want this.
 
What is the value of the IsMdiContainer property of the form that you want to prevent your users from moving?

[vampire][bat]
 
E&f true is the value centralfrm's IsMdiContainer. I have set it via properties window. Its the parent mdi form as i told before.
 
Then, I'm afraid, I really don't understand what is going on.

For the form to open Maximized, set the WindowState property to FormWindowState.Maximized

Disable the various title bar buttons

Now the form cannot be moved, but the form can be "Restored"

The Resize event handler I showed you and/or the MinimumSize mechanism will prevent the form from being "Restored". By using one or (for overkill both) of these you, therefore have a form that simply cannot be moved.

If you have implemented everything that I have suggested, and the form can still be moved - then I give up. I am unable to replicate that scenario, and have no further idea as to a possible solution.

[vampire][bat]
 
E&F what exactly do you mean to disable the various title bar buttons?
Sorry but i still have my problem.
The only way the form can't be moved is if i set the maximizebox to true. And if i do this, the form can be restored and there is a little bit difference between the maximized and the restored mdi parent form.
 
assimang - perhaps the key to the rest of us understanding what you want is to explain in what way Excel is "unmoveable"? Because when Excel is not maximized, it most certainly is moveable.

So perhaps by describing this certain Excel behaviour that you want to imitate, we will understand what you are after.


 
Joe when the excel is maximized is unmovable. And that's the what i want in my program, i want the centralfrm which is the mdi parent form always being maximized. Although, i want the user to be unable to use the maximize button either for restoring either for maximizing the form and if its possible to hide it and have only minimize and close button. And i also want the user to be unable too, to restore or maximize the form via doubleclicking the title bar.
 
This is a form maximized:
This is a form at max size:
With what earthandfire gave you, you should get the first. The first is unmovable. If some how you are not getting the first or you now realize that wasn't what you were talking about please explain in detail or show us some pictures.

-I hate Microsoft!
-Forever and always forward.
 
Sorwen i want the first, but i when i click the maxbutton or dubbleclick in the titlebar i am getting the second.
 
And when i am getting the second the form can be moved.
 
In the forms properties set ControlBox False. I think this was already said, but make sure the WindowState property is set to Maximized. For the moment you can put the WindowState = FormWindowState.Maximized in the forms size event. It will resize then mazimize again. There is a way to stop that, but I can't remember at the moment.

-I hate Microsoft!
-Forever and always forward.
 
Thanks Sorwen but setting controlbox to false allow the user to move the form. And also i can see the mdi parent form's breadcrub. I have explained it so many times, and i feel unhappy noone can't help me.
Once more.
The only way to be my mdi parent form unmovable is set maximized property to true. Setting ControlBox to false is like setting maximize button to false, which means that always the user can move the form. When my form loads i am getting this and the form is unmovable as i want it. Up to here is ok. But when i press either maximized button either dubble click in the title bar i am getting this and the form can be moved.
Well, i don't want a solution which i can see the mdi parent form's breadcrumb or the form to be movable. I just want if the user presses maximize button or if double clicks the title bar to happen nothing. I think i have explained this very clearly. Hope it helps.

Thanks all
in advanced.
 
Thanks Sorwen but setting controlbox to false allow the user to move the form."
Sorry, keep controlbox true and set minimizebox = false. I'm still trying to find the part that would keep it not moving at all. The API earthandfire mentioned looks like it might be the one I used in VBA to do it.

-I hate Microsoft!
-Forever and always forward.
 
Sorwen unfortunately i am still having my problem.
 
E&f I am just thinking if i could get the mdi parent form's size (width, height) when the form is maximized and pass it to MinimumSize New Size function. I don't know if this is a good idea. Although i am waiting for your solution.

Thanks all
again.
 
I thought that someone already had you setting something like that. You still get a slight movement when you do that with resetting the WindowState to maximize as it switches between bordered then back to maximize. Actually I didn't set the min size it just forced the windows default size to the available window size. Something like this in the load event:

Code:
Me.Size = New System.Drawing.Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height) 'make sure that it sets to the work area and doesn't cover up the task bar.
Me.Location = New System.Drawing.Location(0,0) 'make sure top corner is always at the top.

-I hate Microsoft!
-Forever and always forward.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top