Move around Borderless Form

Hi

hiI tried this code but its not working
plz check and reply soon
Private Sub frmDiv_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles Me.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then
Me.Capture = False
Const WM_NCLBUTTONDOWN As Integer = &HA1
Const HTCAPTION As Integer = &H2
Dim m As New Message
m.HWnd = Me.Handle
m.Msg = WM_NCLBUTTONDOWN
m.WParam = HTCAPTION
m.LParam = 0
Me.DefWndProc(m)
End If
End Sub
regards
James
 
Last edited:
That looks very much like exactly the same code as I posted? It works for me, I have attached the working project, see if you can run it move the borderless form - it really does move around when I do it ;)
 

Attachments

  • vbnet20-borderless.zip
    12.4 KB · Views: 25
Right-click.... Insert Snippet.... Window Forms Application ..... Form ..... Move a window by dragging the client area of a form

Adds the following code:
VB.NET:
    Private Sub Me_MouseDown(ByVal sender As Object, _
        ByVal e As MouseEventArgs) _
        Handles MyBase.MouseDown

        mouseOffset = New Point(-e.X, -e.Y)
    End Sub

    Private Sub Me_MouseMove(ByVal sender As Object, _
        ByVal e As MouseEventArgs) _
        Handles MyBase.MouseMove

        If e.Button = MouseButtons.Left Then
            Dim mousePos As Point = Control.MousePosition
            mousePos.Offset(mouseOffset.X, mouseOffset.Y)
            Location = mousePos
        End If
    End Sub

-tg
 
Back
Top