Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27329

VS 2010 How to avoid MDI child move out from MDI parent client area

$
0
0
I want to make my form divide into 3
like this

Code:

--------------------------------------
                    Splitter1
--------------------------------------

                    MDI Parent

--------------------------------------
                  Splitter2
--------------------------------------

The problem is I want to make the Child Form only can move inside the MDI Parent and can't move outside that
I found a code that can prevent this but only work for the top and left, the right and bottom path still have a problem
and also this code make my child form move not like normal ( not smooth )

this is the code
Code:

  Private oldLoc As Point

  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    oldLoc = Me.Location
  End Sub

 Private Sub Form1_Move(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Move
    If Not Me.ParentForm Is Nothing Then
            If Me.Left < Me.ParentForm.ClientRectangle.Left Or _
              Me.Right >= Me.ParentForm.ClientRectangle.Width - 5 Or _
              Me.Top < Me.ParentForm.ClientRectangle.Top Or _
              Me.Bottom >= Me.ParentForm.ClientRectangle.Height - 5 Then
                Me.Location = oldLoc
            Else
                oldLoc = Me.Location
            End If
        End If
    End Sub

so is there other way beside this code that will work well ( top, left, right and bottom ) and more effective ?
please help me

Viewing all articles
Browse latest Browse all 27329

Trending Articles