0

I have a MDI Child form (frmReview) that I aim to show on my maximized parent form with the following code:

Public Sub frmTransport_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
    'keyboard shortcuts
    If e.KeyCode = Keys.F1 Then LaunchManual()
    If e.Control Then
        If e.KeyValue = Keys.R Then
            Me.WindowState = FormWindowState.Maximized
            Dim review As New frmReview
            review.MdiParent = Me
            review.Location = New Point(1175, 0)
            review.BringToFront()
            review.Show()
        End If
        ...
        ...
        End Sub

enter image description here

The point (1175, 0) is the top-right corner where the TabControl meets the Yellow mdi Container. The parent form has its isMdiContainer property set to True and Load event of frmReview does fire when i run this code, but I do not see the child form:

In another program I have, I use to same process to display MDI Child Forms and it works fine. Any suggestions on why this is happening?

Thanks in advance!

  • You know that `Location` corresponds to the top left corner of a control, and you are setting that to the top right corner of the parent? Try (588, 0), it should be in the middle. You just need to do the math for the proper location – djv Aug 03 '17 at 15:52
  • My mistake - set it to (588, 0), still not working – Tyler Braun Aug 03 '17 at 16:05

1 Answers1

1

If you want to display the form in the top right corner, use this

Dim mdiClient = Me.Controls.OfType(Of MdiClient).FirstOrDefault()
Me.WindowState = FormWindowState.Maximized
Dim review As New frmReview
review.MdiParent = Me
review.BringToFront()
review.Show()
' order of Show() call changed so review has a size
review.Location = New Point(mdiClient.Size.Width - review.Width, 0)
djv
  • 15,168
  • 7
  • 48
  • 72
  • I wasn't explicitly trying to show the form in the top-right corner, but this code shows my form. thank you. Could you explain why my code was not working? – Tyler Braun Aug 03 '17 at 16:07
  • Well the order of Show() has some influence. After calling Show it will have an initial size and position. Before it will not. This is why I need this order for my math involving its width... Not sure why your form wasn't shown when called in your original order. Possibly whatever is already on the MDI form was still on top somehow. – djv Aug 03 '17 at 16:17
  • 2
    All I had to do in my original code was move Show() before Location = . Thanks! – Tyler Braun Aug 03 '17 at 16:22
  • Ok.. I could have saved a lot of time :) – djv Aug 03 '17 at 16:24