VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Center an MDI Child Form Within the Parent

by Chris Gibbs (1 Submission)
Category: Complete Applications
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (3 Votes)

useful when you need to center an MDI child form within the parent windo

Inputs
The SUB (CenterChild) requires two arguments. The first of these two arguments is the name of the MDI (parent) form. The second argument is the name of the MDI Child form.

Rate Center an MDI Child Form Within the Parent

Sub CenterChild (Parent As Form, Child As Form)
  Dim iTop As Integer
  Dim iLeft As Integer
  If Parent.WindowState <> 0 Then Exit Sub
  iTop = ((Parent.Height - Child.Height) \ 2)
  iLeft = ((Parent.Width - Child.Width) \ 2)
  Child.Move iLeft, iTop ' (This is more efficient than setting Top and Left properties)
End Sub


The next thing you will need to do is actually call the CenterChild procedure. I have placed the call to CenterChild within the child window's Form_Click event procedure. 

Sub Form_Click ()
  CenterChild MDIForm1, Form1
End Sub

Download this snippet    Add to My Saved Code

Center an MDI Child Form Within the Parent Comments

No comments have been posted about Center an MDI Child Form Within the Parent. Why not be the first to post a comment about Center an MDI Child Form Within the Parent.

Post your comment

Subject:
Message:
0/1000 characters