MDI enquiry

baddy
09-07-2000, 02:54 AM
How do I prevent the MDI parent form from being size?
I want a fixed size MDI parent form.
In addition, when i access a MDI child form through clicking of a button on the parent form, I have a bug. Whenever I re-enter the child form, the form seems to move more and more to the edge.
Can anyone help me with these 2 problems?
Thx !!!

BillSoo
09-07-2000, 01:22 PM
I seem to recall replying to you on something like this once before....

Anyways, look at this code. It's a mdiform with a picturebox and button on it.

Option Explicit
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Const GWL_STYLE = (-16)
Private Const WS_MAXIMIZEBOX = &H10000
Private Const WS_MINIMIZEBOX = &H20000
Private Const WS_THICKFRAME = &H40000

Private Sub Command1_Click()
Form1.Show
Me.Arrange 0
End Sub

Private Sub MDIForm_Initialize()
Dim i&
i& = GetWindowLong(Me.hwnd, GWL_STYLE)
i& = i& And Not WS_MINIMIZEBOX
i& = i& And Not WS_MAXIMIZEBOX
i& = i& And Not WS_THICKFRAME
SetWindowLong Me.hwnd, GWL_STYLE, i&
End Sub

Private Sub MDIForm_Load()
Me.Move Screen.Width / 4, Screen.Height / 4, Screen.Width / 2, Screen.Height / 2
End Sub

The API calls in the initialize event remove the max and min boxes and set the frame to fixed rather than resizeable.

There is also a form1 that is loaded when the command button is pressed. Normally, it will move down and to the right everytime it is loaded because the MDIform is moving it to the next position in the cascade sequence. You can overwrite this by putting positioning code in the form load event or, as above, by resetting the MDIform arrangement.

One method of positioning your form is:
sub form_load()
me.move (me.parent.scalewidth-me.width)/2,(me.parent.scaleheight-me.height)/2
end sub

which should center your child form inside the MDI form


"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum