Page 1 of 1

New Move Borderless form Code

Posted: Sat Mar 20, 2010 8:28 pm
by hungryhounduk
Hi all
Ok i know we have 2 or 3 examples on here for moving borderless forms, well here is another example that you all can you use in your apps if you wish.

Put this after your Public Class Form1 ( or whatever your Form is called )
Code: Select all
Private mouseOffset As Point
Form Mouse Down Code
Code: Select all
 mouseOffset = New Point(-e.X, -e.Y)
Form Mouse Move Code
Code: Select all
If e.Button = Windows.Forms.MouseButtons.Left Then
            Dim mousePos As Point = Control.MousePosition
            mousePos.Offset(mouseOffset.X, mouseOffset.Y)
            Location = mousePos
        End If
and that's it

enjoy cooll;

Chris

Re: New Move Borderless form Code

Posted: Sun Mar 21, 2010 3:04 pm
by Lewis
Well i thought when i saw the title. Whats the point?! And this is the shortest code ive seen ill need to change all of mine now ;) Thanks HH.
Lewis.

Re: New Move Borderless form Code

Posted: Wed Apr 14, 2010 1:31 am
by zachman61
thanks i changed the form1 code to pictureboxes for my xfire utility
:)

Re: New Move Borderless form Code

Posted: Sun Jun 27, 2010 10:03 am
by Livengood
This code runs alot smoother than using a timer :D, thanks hungry :)

Re: New Move Borderless form Code

Posted: Tue Jun 29, 2010 10:27 pm
by Nery
There is another simple way:

Code: Select all
Private point As New Point
Form1_MouseMove:
Code: Select all
Dim it As New Size(e.X - point.X, e.Y - point.Y)
        If (e.Button = MouseButtons.Left) Then
            Me.Location += it
            point = e.Location - it
        Else
            point = e.Location
        End If
    End Sub
And there you go, an ultra smooth and functional way to move a borderless form.