VB中如何做到让窗口无法关闭?

就是点右上角的X无不关闭,写代码

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Cancel = True
End Sub 这个可以一试,不过世界上没有绝对的事。
温馨提示:内容为网友见解,仅供参考
第1个回答  2014-01-10
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 Const MF_REMOVE = &H1000
Private Const SC_CLOSE = &HF060

Function Disabled(ChWnd As Long)
Dim hMenu, hendMenu As Long
Dim c As Long
hMenu = GetSystemMenu(ChWnd, 0)
RemoveMenu hMenu, SC_CLOSE, MF_REMOVE
End Function

'然后在Sub Form_Load()中加入Disabled Me.hwnd即可:
Private Sub Form_Load()
Disabled Me.hwnd
End Sub
第2个回答  2014-01-10
用下面的代码就可以,虽然窗体上有关闭按钮,但就是不能关闭Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Cancel = True
End Sub
第3个回答  2018-12-21
看我来个更有意思的😄
Private Sub Form_Unload(Cancel As Integer)
myexit = MsgBox("看完才能退出哦", vbExclamation + vbYesNo + vbDefaultButton, "哼...")
Cancel = True
End Sub
第4个回答  2014-01-10
form1.Enabled=false但整个窗体都没反应了
相似回答