Search Amazon:

Move a .NET Form that has no title bar

If you have an Irregular form (one that is not the basic rectangular shape) it probably doesn't have a title bar which means the user cannot move it. This code allows you to hold the left mouse button down and drag the form to a new location.

Add these module level variables:

    Private myPointClicked As Point
    Private myIrregular As New clsIrregular()

Add this code:

    Private Sub form1_MouseDown(ByVal sender As Object, _
        ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown

        myFormDragging = True
        myPointClicked = New Point(e.X, e.Y)
    End Sub

    Private Sub form1_MouseUp(ByVal sender As Object, _
        ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp

        myFormDragging = False
    End Sub

    Private Sub form1_MouseMove(ByVal sender As Object, _
        ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove

        If myFormDragging Then
            Dim aMoveToPoint As Point
            '
            ' Use the current mouse position to find the target location.
            '
            aMoveToPoint = Me.PointToScreen(New Point(e.X, e.Y))
            '
            ' Adjust the position based on where you started.
            '
            aMoveToPoint.Offset(myPointClicked.X * -1, _
                (myPointClicked.Y + SystemInformation.CaptionHeight + _
               SystemInformation.BorderSize.Height) * -1)
            '
            ' Move the form.
            '
            Me.Location = aMoveToPoint
        End If
    End Sub

Sign In
  User Id 
  Password 


Submit Your Own Code and Articles




About TheScarms
About TheScarms

Ask me your programming questions

I read every email and answer all I can.

User Feedback: Be the first to add a comment! Items to Show:     

     
You must log in to post feedback.
Comment:    
 

If you use this code, please mention "www.TheScarms.com"

Email this page


TheScarms AppSentinel lets you securely copy protect and create evaluation versions of your software

TheScarms(tm) AppSentinel lets you quickly and easily create evaluation versions of your software and stop unauthorized copying and unregistered use of your programs!

Get your free
trial copy today!


      The World's Number 1 Web Host

© Copyright 2008 TheScarms