How to move form without form border (visual studio)

后端 未结 9 2048
无人共我
无人共我 2020-12-09 13:38

I am making a windows form application in visual studio 2013 Express. In order to make the application look more customized and attractive, I designed the forms in my applic

9条回答
  •  無奈伤痛
    2020-12-09 13:50

    Try this:

    Public Const WM_NCLBUTTONDOWN As Integer = &HA1 
    Public Const HT_CAPTION As Integer = &H2 
    
     _ 
    Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
    End Function
    
     _ 
    Public Shared Function ReleaseCapture() As Boolean
    End Function
    
    Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown, Panel1.MouseDown 
        If e.Button = Windows.Forms.MouseButtons.Left Then
            ReleaseCapture() 
            SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0) 
        End If
    End Sub
    

    It uses the Windows API calls to tell the window that the user is holding the window. As you can see is attached to the Form MouseDown event, but you can use any control you want to use to drag the form.

提交回复
热议问题