Results 1 to 6 of 6

Thread: Moving a form without a titlebar

Threaded View

  1. #1

    Thread Starter
    Fanatic Member Emcrank's Avatar
    Join Date
    Jan 2009
    Posts
    566

    Moving a form without a titlebar

    To make a form movable when it has no titlebar
    Use
    VB.NET Code:
    1. #Region " MoveFormWithoutTitleBar "
    2. Const WS_MAXIMIZEBOX As Integer = &H10000
    3.  
    4.     Const GWL_STYLE As Integer = -16
    5.  
    6.     Const WM_NCHITTEST As Integer = &H84
    7.  
    8.     Const HTCLIENT As Integer = &H1
    9.  
    10.     Const HTCAPTION As Integer = &H2
    11.     <System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint:="SetWindowLong")> _
    12.  
    13.     Public Shared Function SetWindowLong(<System.Runtime.InteropServices.InAttribute()> ByVal hWnd As System.IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As UInt64) As Integer
    14.  
    15.     End Function
    16.  
    17. <System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint:="GetWindowLong")> _
    18.  
    19.     Public Shared Function GetWindowLong(<System.Runtime.InteropServices.InAttribute()> ByVal hWnd As System.IntPtr, ByVal nIndex As Integer) As UInt64
    20.  
    21.     End Function
    22.  
    23.     'Example in a button click event - form load event may be more appropriate
    24.  
    25.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    26.  
    27.         Dim Result As UInt64 = GetWindowLong(Me.Handle, GWL_STYLE)
    28.  
    29.         Result = (Result And Not CULng(WS_MAXIMIZEBOX))
    30.  
    31.         SetWindowLong(Me.Handle, GWL_STYLE, Result)
    32.  
    33.  
    34.     End Sub
    35.  
    36.  
    37.     Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
    38.  
    39.         Select Case m.Msg
    40.  
    41.             Case WM_NCHITTEST
    42.  
    43.                 MyBase.WndProc(m)
    44.  
    45.                 If CInt(m.Result) = HTCLIENT Then
    46.  
    47.                     m.Result = New IntPtr(HTCAPTION)
    48.  
    49.                 End If
    50.  
    51.             Case Else
    52.  
    53.                 MyBase.WndProc(m)
    54.  
    55.         End Select
    56.  
    57.     End Sub
    58. #End Region

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width