在表单设计器中,将Form.ControlBox属性设置为 false。
这使菜单完全消失:
您可以禁用代码中的不同元素,但按钮似乎与菜单绑定,因此在不停止等效按钮工作的情况下似乎无法摆脱菜单:
Public Class Form1
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Integer, ByVal revert As Integer) As Integer
Private Declare Function EnableMenuItem Lib "user32" (ByVal menu As Integer, ByVal ideEnableItem As Integer, ByVal enable As Integer) As Integer
Private Declare Function RemoveMenu Lib "user32" Alias "RemoveMenu" (ByVal hMenu As IntPtr, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
Private Const SC_CLOSE = &HF060& 'Closes the window
Private Const MF_BYCOMMAND = &H0& 'Specifies that the parameter gives the command ID of the existing menu item
Private Const SC_SIZE = &HF000& 'Sizes the window
Private Const SC_MOVE = &HF010& 'Move the window
Private Const SC_MINIMIZE = &HF020& 'Minimizes Window
Private Const SC_MAXIMIZE = &HF030& 'Maximizes window
Private Const SC_RESTORE = &HF120& 'Restores window
Private Const MF_SEPARATOR = &H800& ' Menu Separator
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
EnableMenuItem(GetSystemMenu(Me.Handle.ToInt32, 0), SC_CLOSE, MF_BYCOMMAND)
RemoveMenu(GetSystemMenu(Me.Handle, False), 0, MF_SEPARATOR)
RemoveMenu(GetSystemMenu(Me.Handle, False), SC_CLOSE, MF_BYCOMMAND)
RemoveMenu(GetSystemMenu(Me.Handle, False), SC_SIZE, MF_BYCOMMAND)
RemoveMenu(GetSystemMenu(Me.Handle, False), SC_MOVE, MF_BYCOMMAND)
RemoveMenu(GetSystemMenu(Me.Handle, False), SC_MINIMIZE, MF_BYCOMMAND)
RemoveMenu(GetSystemMenu(Me.Handle, False), SC_MAXIMIZE, MF_BYCOMMAND)
RemoveMenu(GetSystemMenu(Me.Handle, False), SC_RESTORE, MF_BYCOMMAND)
End Sub
End Class