To make a form movable when it has no titlebar
Use
VB.NET Code:
#Region " MoveFormWithoutTitleBar "
Const WS_MAXIMIZEBOX As Integer = &H10000
Const GWL_STYLE As Integer = -16
Const WM_NCHITTEST As Integer = &H84
Const HTCLIENT As Integer = &H1
Const HTCAPTION As Integer = &H2
<System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint:="SetWindowLong")> _
Public Shared Function SetWindowLong(<System.Runtime.InteropServices.InAttribute()> ByVal hWnd As System.IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As UInt64) As Integer
End Function
<System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint:="GetWindowLong")> _
Public Shared Function GetWindowLong(<System.Runtime.InteropServices.InAttribute()> ByVal hWnd As System.IntPtr, ByVal nIndex As Integer) As UInt64
End Function
'Example in a button click event - form load event may be more appropriate
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Result As UInt64 = GetWindowLong(Me.Handle, GWL_STYLE)
Result = (Result And Not CULng(WS_MAXIMIZEBOX))
SetWindowLong(Me.Handle, GWL_STYLE, Result)
End Sub
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
Select Case m.Msg
Case WM_NCHITTEST
MyBase.WndProc(m)
If CInt(m.Result) = HTCLIENT Then
m.Result = New IntPtr(HTCAPTION)
End If
Case Else
MyBase.WndProc(m)
End Select
End Sub
#End Region