0

Hi I have a mdi child form (form A) which when clicked displays another mdi child formn(form B) both of which share the same parent form. The problem is I cant find a way to center the child form B to child form A? Is this even allowed in vb.net? I can however display form B (as a non mdi child) centered to form A (as a mdi child form) which is strange. an though this could work this issue now is that the forms boarder within Windows 8 at least, is visually totally different to a mdi form in windows 8 making the whole thing look un-uniformed and messy?

LabRat
  • 1,996
  • 11
  • 56
  • 91
  • How do you display non mdi child from in center? – Chetan Jun 13 '19 at 16:29
  • just by placing it under a button found in Child form A with the following code: FormB.Show() then In Form B at the load event I center the forms with Dim x As Integer = ((FormA.Width / 2) - (Me.Width / 2)) Dim y As Integer = ((FormA.Height / 2) - (Me.Height / 2)) Me.Location = New Point(x, y) – LabRat Jun 13 '19 at 16:53
  • Mind you thats not an issue. The issue is that if I show Form B as a mdi and show Form A as a mdi Form B wont center to Form A eventhough they share the same Parrent form – LabRat Jun 13 '19 at 16:57

1 Answers1

0

Here's one way to accomplish it:

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
Idle_Mind
  • 38,363
  • 3
  • 29
  • 40