Perfect native borderless form moving using any control

Posts 1–13 of 13 · Page 1 of 1
Perfect native borderless form moving using any control
Alright guys,

I've finally found a way to create PERFECT borderless form moving that uses the NATIVE Windows Form moving method. The other method where it just checks if your mouse is down and moves with your mouse is BUGGY. Load up a form then shake your mouse around while moving the it and you will see your mouse has moved it's position on the form.

I was hesitant to release this, but here you go. Don't leech it.

Put this at the top of your code:
Code:
Imports System.Runtime.InteropServices


Put this inside your class, not inside a sub:
Code:
<DllImport("user32.dll")> _
Public Shared Function ReleaseCapture() As Boolean
End Function
<DllImport("user32.dll")> _
Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
End Function

Put this in your control's Click, MouseDown, and MouseMove events:
Code:
ReleaseCapture()
SendMessage(Handle, &HA1, &H2, 0)
Credits: Me and Aaron
Quote Originally Posted by DawgiiStylz View Post
Works nicely
Great! I'm glad to help
Please Credit me when you use it!
Quote Originally Posted by Matroix73 View Post
Please Credit me when you use it!
Credit you for something that comes with the native Windows API?
No.
Thank you for pointing this feature out?
Sure, why not, but forcing someone to credit you for telling them about Window's native features is pretty leechy, since Microsoft coded said features in the original C/C++/what ever windows was compiled in.

I'm not saying this to be mean, but to point out that you do not "personally" own the code, as it's just using the API which does all the work.
Quote Originally Posted by rileyjstrickland View Post
Credit you for something that comes with the native Windows API?
No.
Thank you for pointing this feature out?
Sure, why not, but forcing someone to credit you for telling them about Window's native features is pretty leechy, since Microsoft coded said features in the original C/C++/what ever windows was compiled in.

I'm not saying this to be mean, but to point out that you do not "personally" own the code, as it's just using the API which does all the work.
well, so if I force someone to credit me, so I'd make this in private, or even release it in private (PM me for the code)
and crediting me is your own choice...
Quote Originally Posted by Matroix73 View Post
well, so if I force someone to credit me, so I'd make this in private, or even release it in private (PM me for the code)
and crediting me is your own choice...
That sentence was an utter failure.

Please type logical, coherent, English sentences.
Quote Originally Posted by shindereki View Post
thank you.......
You welcome.
Well.

I use:
Code:
 Declare Function ReleaseCapture Lib "user32" () As IntPtr
    Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As IntPtr, ByVal wParam As IntPtr, ByRef lParam As Object) As IntPtr
    Const WM_NCLBUTTONDOWN = &HA1
    Const HTCAPTION = 2

    Private Sub MovePosition(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Form1.MouseDown, Label1.MouseDown', ...
        ReleaseCapture()
        SendMessage(Handle, CType(WM_NCLBUTTONDOWN, IntPtr), CType(HTCAPTION, IntPtr), 2)
    End Sub
It's better and easier to use.
And that what "you (... -.- Sure ...)" have RELEASED here I find 1000x in Google.
It's more of thank you for your contribution to this section.
Code:
<DllImport("user32.dll")> _
    Public Shared Function ReleaseCapture() As Boolean
    End Function


    <DllImport("user32.dll")> _
    Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
    End Function


    Private Const WM_NCLBUTTONDOWN As Integer = &HA1
    Private Const HTCAPTION As Integer = 2

   Private Sub PictureBox1_MouseDown(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseDown
        If e.Button = Windows.Forms.MouseButtons.Left And Me.WindowState <> FormWindowState.Maximized Then
            MoveForm()
        End If
    End Sub


    Private Sub MoveForm()
        ReleaseCapture()
        SendMessage(Me.Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0)
    End Sub
hehe
Posts 1–13 of 13 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us