How to center MDI child Form ?

Hai Experts,

How can i center MDI child Form in its Parent MDI from Without using the size of MDI parent form. i don't want this- ParentMDIFormwidth/2-MDIChildWidth/2

Is there any method



Answer this question

How to center MDI child Form ?

  • mithya

    Thank you halfazner, I also found out you can use

    childForm.SetBounds(l, t, childForm.Width, childForm.Height);

    , where l = (mdiForm.ClientSize.Width - childForm.Width) / 2;
    t = (mdiForm.ClientSize.Height - childForm.Height) / 2;

    Aside...I am surprised the original answer was accepted, the original question was

    "...Without using the size of MDI parent form. i don't want this- ParentMDIFormwidth/2-MDIChildWidth/2"

    You cant get away from this...


  • kweeyen

    this.StartPosition = FormStartPosition.CenterParent

    under which event is one supposed to put the above line

    I tried form_load, form_shown, form_paint events in the mdi child form, none of it works !


  • Kache4

    form.StartPosition = FormStartPosition.CenterParent

  • NS_DICK

    Thank You
  • ACorbs

    can you please teach me how to do it

    I copy and paste the code, and when I run the program that block of code became a red text...


  • Ritesh Parikh

    joedotnot,

    The answer is after the point in which you add the MDI Child userform to the Parent userform:

    'Add this segment of code to your parent form
    Dim MDIChild As New Form2()
    'Replace Form2() with the name of your child form
    MDIChild.MdiParent = Me
    MDIChild.Show()
    Application.DoEvents()
    MDIChild.Location = New Point(Me.Width / 2 - MDIChild.Width / 2, Me.Height / 2 - MDIChild.Height / 2)

    I found you must set the location after you Show() the MDIChild.
    Application.DoEvents() ensures the above code completes before continuing, it's not neccessary.

    Hope this helps,
    halfazner


  • How to center MDI child Form ?