Home All Groups Group Topic Archive Search About

MDI Child start position

Author
9 Oct 2006 10:54 AM
mabond
Hi

Why is my mdichild form not starting in the "centerparent" position? I'm
using the following:

Public Class frmCAD
    Private Sub MakeNewCallToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
MakeNewCallToolStripMenuItem.Click
        Dim frmNew As New frmMakeNewCall()
        frmNew.MdiParent = Me
        frmNew.StartPosition = FormStartPosition.CenterParent
        frmNew.Show()
    End Sub
End Class

Thanks

Michael Bond

Author
10 Oct 2006 2:48 AM
teslar91
MDI children ignore the StartPosition property, as well as any other
attempt to set their position prior to .Show.

Put this in the Load event of every MDI child form you want centered:

  CenterInParent(Me)

And this in a module:

  Sub CenterInParent(ByRef frm As Object)
    frm.Left = Higher((frm.Parent.ClientSize.Width - frm.Width) / 2, 0)
    frm.Top = Higher((frm.Parent.ClientSize.Height - frm.Height) / 2,
0)
  End Sub

  Function Higher(ByRef x, ByRef y)
    Higher = IIf(x > y, x, y)
  End Function
Author
10 Oct 2006 9:58 AM
mabond
Hi

thanks for that.......

suppose I shouldn't ask, but if the MDI children ignore the StartPosition
property why provide a "centreparent" option for the startposition ????.
Answers on a postcard to Microsoft.com please

Thanks again

Michael




Show quoteHide quote
"tesla***@hotmail.com" wrote:

> MDI children ignore the StartPosition property, as well as any other
> attempt to set their position prior to .Show.
>
> Put this in the Load event of every MDI child form you want centered:
>
>   CenterInParent(Me)
>
> And this in a module:
>
>   Sub CenterInParent(ByRef frm As Object)
>     frm.Left = Higher((frm.Parent.ClientSize.Width - frm.Width) / 2, 0)
>     frm.Top = Higher((frm.Parent.ClientSize.Height - frm.Height) / 2,
> 0)
>   End Sub
>
>   Function Higher(ByRef x, ByRef y)
>     Higher = IIf(x > y, x, y)
>   End Function
>
>