📄 form1.vb
字号:
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
'窗体重写 dispose 以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.CheckBox1 = New System.Windows.Forms.CheckBox
Me.SuspendLayout()
'
'CheckBox1
'
Me.CheckBox1.Location = New System.Drawing.Point(88, 96)
Me.CheckBox1.Name = "CheckBox1"
Me.CheckBox1.Size = New System.Drawing.Size(128, 24)
Me.CheckBox1.TabIndex = 1
Me.CheckBox1.Text = "隐藏和显示标题栏"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.CheckBox1)
Me.Name = "Form1"
Me.Text = "隐藏和显示标题栏"
Me.ResumeLayout(False)
End Sub
#End Region
Private Function TitleBar(ByVal bState As Boolean) As Object
Dim lStyle As Integer
Dim tR As RECT
GetWindowRect(Me.Handle.ToInt32, tR)
'得到窗体的区域保存在tr中
lStyle = GetWindowLong(Me.Handle.ToInt32, GWL_STYLE)
'得到窗体目前的风格设置
If (bState) Then
'如果显示标题栏
Me.Text = Me.Tag
'设置Caption属性
If Me.ControlBox Then
lStyle = lStyle Or WS_SYSMENU
'设置显示系统菜单
End If
If Me.MaximizeBox Then
lStyle = lStyle Or WS_MAXIMIZEBOX
'设置显示最大化按钮
End If
If Me.MinimizeBox Then
lStyle = lStyle Or WS_MINIMIZEBOX
'设置显示最小化按钮
End If
If Me.Text <> "" Then
lStyle = lStyle Or WS_CAPTION
'显示窗口的标题
End If
Else
'如果隐藏标题栏
Me.Tag = Me.Text
'将窗口标题保存到窗口的tag属性中
Me.Text = ""
'将窗口标题设置为空字符串
lStyle = lStyle And Not WS_SYSMENU
'隐藏系统菜单
lStyle = lStyle And Not WS_MAXIMIZEBOX
'隐藏最大化按钮
lStyle = lStyle And Not WS_MINIMIZEBOX
'隐藏最小化按钮
lStyle = lStyle And Not WS_CAPTION
'隐藏标题
End If
SetWindowLong(Me.Handle.ToInt32, GWL_STYLE, lStyle)
'设置窗体风格
SetWindowPos(Me.Handle.ToInt32, 0, tR.Left_Renamed, tR.Top, tR.Right_Renamed - tR.Left_Renamed, tR.Bottom - tR.Top, Module1.ESetWindowPosStyles.SWP_NOREPOSITION Or Module1.ESetWindowPosStyles.SWP_NOZORDER Or Module1.ESetWindowPosStyles.SWP_FRAMECHANGED)
'保证窗口具有相同的大小
End Function
Private Sub CheckBox1_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles CheckBox1.CheckStateChanged
If CheckBox1.CheckState = 1 Then
TitleBar(False)
Else
TitleBar(True)
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -