Results 1 to 17 of 17

Thread: Moving a Borderless form, simple & short.

Threaded View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Moving a Borderless form, simple & short.

    First of all credits go to CoderJoe though he isn't active.

    Here is the code:

    vb Code:
    1. Public Class Form1
    2.     'Declare the variables
    3.     Dim drag As Boolean
    4.     Dim mousex As Integer
    5.     Dim mousey As Integer
    6.  
    7.     Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
    8.         drag = True 'Sets the variable drag to true.
    9.         mousex = Windows.Forms.Cursor.Position.X - Me.Left 'Sets variable mousex
    10.         mousey = Windows.Forms.Cursor.Position.Y - Me.Top 'Sets variable mousey
    11.     End Sub
    12.  
    13.     Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
    14.         'If drag is set to true then move the form accordingly.
    15.         If drag Then
    16.             Me.Top = Windows.Forms.Cursor.Position.Y - mousey
    17.             Me.Left = Windows.Forms.Cursor.Position.X - mousex
    18.         End If
    19.     End Sub
    20.  
    21.     Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
    22.         drag = False 'Sets drag to false, so the form does not move according to the code in MouseMove
    23.     End Sub
    24. End Class

    You can place the code on the events of any control. Say if you would like to use an image as a title bar, then just place the code on the appropiate events of the image.
    Last edited by noahssite; Sep 13th, 2008 at 07:52 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width