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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mdi form resizing question

Status
Not open for further replies.

csutton

Programmer
Dec 27, 2000
213
0
0
US
Hi everyone,

I have found the previous questions and answers on centering a child mdi form within the parent. However, I would also like to be able to resize the active child (whatever one happens to be active) to be the center of the parent. I tried doing this in the resize event, but cannot figure out my objects correctly. I did try using the reference of mdiparent.activeform but it doesn't seem to be working for me..

Any help?? thanks!
 
Try


Private Sub Form_Load()
Me.Move (MDIForm1.ScaleWidth - Me.Width) / 2, (MDIForm1.ScaleHeight - Me.Height) / 2
End Sub


Hope this helps you
Carlos Paiva
 
I do not see where that will trigger if the MDI parent is the one resized.
 
In the resize event of MDI form, test if desired form is loaded, and if so, execute then the changed code from there:

Formxxx.Move (me.ScaleWidth - Formxxx.Width) / 2, (me.ScaleHeight - Formxxx.Height) / 2
 
I do appreciate your time in answering. The issue is, it could be any number of forms that would be open, but it is only going to be 1 form at a time.

So I would like to be able to resize whatever the active form is at that time w/o having to do a bunch of if/then statements to test (I would imagine that being inefficient).

I just can't seem to figure out the proper reference and declarations to use on the parent form to locate the child form in a proper spot... Thank you !!
 
If you are sure that only one is open at a time do this way

'Parse forms collection

dim f as form

'This will retrieve a reference for each loaded forms

for each f in Forms
f.move ...
next

If you need anything more just say,
I'm here to help and whenever is possible, be helped!

Carlos Paiva
 

Give this a try...
[tt]
Private Sub MDIForm_Resize()

Dim F As Form

For Each F In Forms
If TypeOf F Is MDIForm Then
Else
If F Is ActiveForm Then
F.Move (MDIForm1.Width / 2) - (F.Width / 2), (MDIForm1.Height / 2) - (F.Height / 2)
End If
End If
Next


End Sub
[/tt]

Good Luck

 
If you want to move/resize only the active form then this will be the code.

Private Sub MDIForm_Resize()

If Not MDIForm1.ActiveForm Is Nothing Then
MDIForm1.ActiveForm.Move (Me.ScaleWidth - MDIForm1.ActiveForm.Width) / 2, (Me.ScaleHeight - MDIForm1.ActiveForm.Height) / 2
End If

End Sub

But, if you want to move all the open form then this will be the code.

Private Sub MDIForm_Resize()

Dim f As Form

For Each f In Forms

'Check if the current form is the Not then MDI Form
If Not f.Name = "MDIForm1" Then
f.Move (Me.ScaleWidth - f.Width) / 2, (Me.ScaleHeight - f.Height) / 2
End If

Next f

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top