MDI子表单不会在同一个范围内居中于另一个MDI子表单?

时间:2019-06-13 16:27:15

标签: vb.net forms mdichild mdiparent

嗨,我有一个mdi子窗体(窗体A),单击该窗体会显示另一个mdi子窗体(窗体B),它们都共享相同的父窗体。问题是我找不到将子窗体B居中到子窗体A的方法? vb.net甚至允许这样做吗?但是,我可以将表格B(作为非mdi子窗体)居中显示为表格A(作为mdi子窗体),这很奇怪。尽管这现在可以解决此问题,但至少是Windows 8中的表单寄宿者在视觉上与Windows 8中的mdi表单在视觉上完全不同,从而使整个事情看起来不一致且混乱。

1 个答案:

答案 0 :(得分:0)

这是完成任务的一种方法:

Public Class MdiChildA

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim childB As New MdiChildB
        childB.MdiParent = Me.MdiParent
        AddHandler childB.Load, AddressOf child_Load
        childB.Show()
    End Sub

    Private Sub child_Load(sender As Object, e As EventArgs)
        Dim otherChild As Form = DirectCast(sender, Form)
        otherChild.StartPosition = FormStartPosition.Manual
        otherChild.Location = New Point((Me.Location.X + Me.Size.Width / 2) - otherChild.Size.Width / 2,
                                        (Me.Location.Y + Me.Size.Height / 2) - otherChild.Size.Height / 2)
    End Sub

End Class