在VB窗体中去掉关闭按钮的方法?

VB窗体标题栏上有一个关闭按钮,怎么去掉?
2024-12-13 21:30:28
推荐回答(5个)
回答1:

在VB6.0窗体中去掉关闭按钮的方法:

  1. 在窗体属性窗口设置ControlBox 属性为False。

    ControlBox 属性,返回或设置一个值,指示在运行时控制菜单框是否在窗体中显示。在运行时为只读。

  2. 在窗体属性窗口设置BorderStyle 属性为0,使窗体没有边框或与边框相关的元素。

  3. 在窗体的UnLoad事件代码中使用Cancel = -1语句,使关闭按钮失效。

    Private Sub Form_Unload(Cancel As Integer)
        Cancel = -1 '或Cancel = True
    End Sub

回答2:

在属性窗口中切换到窗体的属性设置,然后在 BorderStyle 选项里选择
0-none 就可以把那个讨厌的小按钮给删了,不过整个标题栏也没有了!

回答3:

controlbox设为FALSE

回答4:

Option Explicit

Private Const MF_BYCOMMAND = &H0&
Private Const MF_BYPOSITION = &H400&
Private Const MF_DISABLED = &H2&
Private Const MF_ENABLED = &H0&
Private Const MF_GRAYED = &H1&

Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long

Private Sub Command1_Click()
Call DisableCloseMenu(Me.hwnd)
End Sub

Private Sub Command2_Click()
Call EnableCloseMenu(Me.hwnd)
End Sub

Private Function DisableCloseMenu(ByVal dwMenu As Long) As Boolean
Dim hMenu As Long
Dim nCount As Long

DisableCloseMenu = False

hMenu = GetSystemMenu(dwMenu, False)
If hMenu <> 0 Then
nCount = GetMenuItemCount(hMenu)
If RemoveMenu(hMenu, nCount - 1, MF_DISABLED Or MF_BYPOSITION) <> 0 Then
If DrawMenuBar(dwMenu) <> 0 Then
DisableCloseMenu = True
End If
End If
End If
End Function

Private Function EnableCloseMenu(ByVal dwMenu As Long) As Boolean
Dim hMenu As Long

EnableCloseMenu = False

hMenu = GetSystemMenu(dwMenu, True)
If hMenu = 0 Then
If DrawMenuBar(dwMenu) <> 0 Then
EnableCloseMenu = True
End If
End If
End Function

回答5:

通过窗体属性修改