Advertisement
2002C Complete Applications #8648

Center an MDI Child Form Within the Parent

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

AI

ملخص الذكاء الاصطناعي: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

كود المصدر
original-source
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
التعليقات الأصلية (3)
مسترجع من Wayback Machine