New Move Borderless form Code

Use this board to post your code snippets - tips and tricks
5 posts Page 1 of 1
Contributors
User avatar
hungryhounduk
VIP - Site Partner
VIP - Site Partner
Posts: 2870
Joined: Mon Jul 27, 2009 11:58 am

New Move Borderless form Code
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
Image
Lewis
Coding God
Coding God
Posts: 1564
Joined: Sun Dec 20, 2009 2:12 pm

Re: New Move Borderless form Code
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.
Image
User avatar
zachman61
VIP - Donator
VIP - Donator
Posts: 1891
Joined: Wed Dec 16, 2009 9:56 pm

Re: New Move Borderless form Code
zachman61
thanks i changed the form1 code to pictureboxes for my xfire utility
:)
Nailing my feet to the floor is easier than using my own muscles to balance, but you don't see me doing that :)
User avatar
Livengood
Serious Programmer
Serious Programmer
Posts: 444
Joined: Tue Feb 16, 2010 6:24 am

Re: New Move Borderless form Code
Livengood
This code runs alot smoother than using a timer :D, thanks hungry :)
Image
User avatar
Nery
Co-Admin Moderator
Co-Admin Moderator
Posts: 1117
Joined: Mon Sep 07, 2009 8:11 pm

Re: New Move Borderless form Code
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.
5 posts Page 1 of 1
Return to “Quick Snips”