In my program, I want the user to be able to move an MDI child window anywhere inside the MDI container but I need it to be kept completely inside the container boundary. For example, the upper left corner should never be at a location less than 0,0 when moved left or up. Currently, if I slide the child window too far left, it extends outside of the MDI container window and the MDI container shows the bottom scroll bar.

Is there a way to prevent the child window from moving outside of the boundaries of the container window? I tried adding code to the .move (see below) so that if the new location was less than 0,0 then it reset it to 0,0 but then the child window controls flicker as the window is moved beyond 0,0 and the logic moves it back to 0,0. It appears that even though the code changes the location to 0,0 and the window shows the child moved to 0,0, when the mouse moves again, the window jump back to its unmoved location.

Private Sub MyForm_Move(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Move

        If Location.X < 0 Then
            Location = New Point(0, Location.Y)
        End If
        If Location.Y < 0 Then
            Location = New Point(Location.X, 0)
        End If
    End Sub

Recommended Answers

All 2 Replies

if you want the child form in your Mdi Parent form then try this code . it will not come out of that mdi parent form.you have to just set the Mdi parent for your child form.
let X be the Mdi Parent and Y,Z be the Chile then

''on the menu clikc of X MdiParent form i'll call y or z

Private Sub YToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SuppliersToolStripMenuItem.Click
        
        Dim y = New yform
        y.MdiParent = Me
        y.Show()
        y.BringToFront()
    End Sub

That is what I have, however, this still allows part of the child window to go beyond the side of the container. In other words, can drag the child window so the upper left corner is at location (-100, 0) and end up with only the right half of the child window showing.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.