VB 让窗口的关闭按钮变灰
4个回答
2013-08-11
展开全部
好像不能禁用关闭按钮的,只能禁用最大化、最小化按钮。属性框中有两个项:MinButton和MaxButton,改成False就行了还有一个方法,选择BorderStyle的值也能改变(就是不能禁用关闭按钮)
2013-08-11
展开全部
使用enable属性即可,如x.enable=false就变得不可用了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-08-11
展开全部
禁止x按钮及关闭菜单
Option Explicit
Private Declare Function GetSystemMenu Lib "user32"_
(ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Declare Function GetMenuItemCount Lib "user32"_
(ByVal hMenu 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 Const MF_BYPOSITION = &H400&
Private Const MF_REMOVE = &H1000&
Private Sub DisableX()
Dim hMenu As Long
Dim nCount As Long
hMenu = GetSystemMenu(Me.hWnd, 0)
nCount = GetMenuItemCount(hMenu)
'Get rid of the Close menu and its separator
Call RemoveMenu(hMenu, nCount - 1, MF_REMOVE Or MF_BYPOSITION)
Call RemoveMenu(hMenu, nCount - 2, MF_REMOVE Or MF_BYPOSITION)
'Make sure the screen updates
'our change DrawMenuBar Me.hWnd
End Sub
Private Sub Form_Load()
DisableX
End Sub
Private Sub Form_Click()
'We need a way out, since the X button'doesn't work :-)
Unload Me
End Sub 在VB中,每个窗体都有两个卸载事件,不同的是,QueryUnload事件不仅允许用户
取消进程,并且告诉程序做些什么来开始卸载工作。为使窗体右上角的X失效,并
下面的代码放在该事件中就行了。
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Cancel = -1
End Sub
Option Explicit
Private Declare Function GetSystemMenu Lib "user32"_
(ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Declare Function GetMenuItemCount Lib "user32"_
(ByVal hMenu 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 Const MF_BYPOSITION = &H400&
Private Const MF_REMOVE = &H1000&
Private Sub DisableX()
Dim hMenu As Long
Dim nCount As Long
hMenu = GetSystemMenu(Me.hWnd, 0)
nCount = GetMenuItemCount(hMenu)
'Get rid of the Close menu and its separator
Call RemoveMenu(hMenu, nCount - 1, MF_REMOVE Or MF_BYPOSITION)
Call RemoveMenu(hMenu, nCount - 2, MF_REMOVE Or MF_BYPOSITION)
'Make sure the screen updates
'our change DrawMenuBar Me.hWnd
End Sub
Private Sub Form_Load()
DisableX
End Sub
Private Sub Form_Click()
'We need a way out, since the X button'doesn't work :-)
Unload Me
End Sub 在VB中,每个窗体都有两个卸载事件,不同的是,QueryUnload事件不仅允许用户
取消进程,并且告诉程序做些什么来开始卸载工作。为使窗体右上角的X失效,并
下面的代码放在该事件中就行了。
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Cancel = -1
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-08-11
展开全部
Private Sub Form_Unload(Cancel As Integer)
Cancel = 1
End Sub
让X无效
Cancel = 1
End Sub
让X无效
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询