Public Class Form1
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As IntPtr, ByVal nIndex As Integer) As Integer
Private Const GWL_STYLE As Integer = (-16)
Private Const WS_CAPTION As Integer = &HC00000 'use this to hide TitleBar Text/Icons etc
Private Const WS_DLGFRAME As Integer = &H400000 'use this to hide TitleBar
Private InitialStyle As Integer
Private BorderStyle As FormBorderStyle
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
BorderStyle = Me.FormBorderStyle
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedDialog
InitialStyle = GetWindowLong(Me.Handle, GWL_STYLE)
SetWindowLong(Me.Handle, -16, InitialStyle And Not WS_DLGFRAME)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
SetWindowLong(Me.Handle, GWL_STYLE, InitialStyle)
Me.FormBorderStyle = BorderStyle
End Sub
'To create a form with no TitleBar
'Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams
' Get
' Dim cp As CreateParams = MyBase.CreateParams
' cp.Style = cp.Style And Not WS_DLGFRAME
' Return cp
' End Get
'End Property
End Class