如何禁用“退出”按钮按钮? [英] How to disable the "Exit" button ?

查看:130
本文介绍了如何禁用“退出”按钮按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在表单中禁用退出按钮。

但是,分钟。最多按钮需要保留


如何?

非常感谢

来自Agnes

I need to disable the exit button in the form .
However, the min. and max. button need to keep it

How ?
Thanks a lot
From Agnes

推荐答案

*" Agnes" < AG *** @ dynamictech.com.hk> scripsit:
* "Agnes" <ag***@dynamictech.com.hk> scripsit:
我需要在表单中禁用退出按钮。
但是,分钟。最多按钮需要保留它
I need to disable the exit button in the form .
However, the min. and max. button need to keep it




\\\

私有声明自动功能GetSystemMenu Lib" user32.dll" (_

ByVal hWnd As IntPtr,_

ByVal bRevert As Int32 _

)作为IntPtr


私有声明自动功能GetMenuItemCount Lib" user32.dll" (_

ByVal hMenu作为IntPtr _

)作为Int32

私有声明自动函数DrawMenuBar Lib" user32.dll" (_

ByVal hWnd As IntPtr _

)作为Int32

私有声明自动功能RemoveMenu Lib" user32.dll" (_

ByVal hMenu作为IntPtr,_

ByVal nPosition作为Int32,_

ByVal wFlags作为Int32 _

)作为Int32


私有Const MF_REMOVE为Int32 =& H1000


私人小组RemoveCloseButton(BYVAL frmForm如表格)

尺寸HMENU作为IntPtr的,正如的Int32

HMENU = GetSystemMenu(frmForm.Handle,0)

如果不是hMenu.Equals(IntPtr.Zero)那么

n = GetMenuItemCount(hMenu)

如果n> 0然后

RemoveMenu(HMENU中,n - 1,MF_BYPOSITION或者MF_REMOVE)

RemoveMenu(HMENU,N - 2,MF_BYPOSITION或者MF_REMOVE)

DrawMenuBar(frmForm.Handle)

结束如果

结束如果

结束子

///


-

Herfried K. Wagner [MVP]

< URL:http://dotnet.mvps.org/>



\\\
Private Declare Auto Function GetSystemMenu Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal bRevert As Int32 _
) As IntPtr

Private Declare Auto Function GetMenuItemCount Lib "user32.dll" ( _
ByVal hMenu As IntPtr _
) As Int32

Private Declare Auto Function DrawMenuBar Lib "user32.dll" ( _
ByVal hWnd As IntPtr _
) As Int32

Private Declare Auto Function RemoveMenu Lib "user32.dll" ( _
ByVal hMenu As IntPtr, _
ByVal nPosition As Int32, _
ByVal wFlags As Int32 _
) As Int32

Private Const MF_BYPOSITION As Int32 = &H400
Private Const MF_REMOVE As Int32 = &H1000

Private Sub RemoveCloseButton(ByVal frmForm As Form)
Dim hMenu As IntPtr, n As Int32
hMenu = GetSystemMenu(frmForm.Handle, 0)
If Not hMenu.Equals(IntPtr.Zero) Then
n = GetMenuItemCount(hMenu)
If n > 0 Then
RemoveMenu(hMenu, n - 1, MF_BYPOSITION Or MF_REMOVE)
RemoveMenu(hMenu, n - 2, MF_BYPOSITION Or MF_REMOVE)
DrawMenuBar(frmForm.Handle)
End If
End If
End Sub
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>


Agnes写道:
Agnes wrote:
我需要禁用表单中的退出按钮。
I need to disable the exit button in the form .




你可以,但在99%的应用程序中你不应该。它与

相同,就像在汽车刹车踏板下安装砖块一样,确保它总是足够快。


那X不是一个退出按钮,它是一个关闭按钮(它关闭了一个

窗口)。大多数VB应用程序确实在最后一个

窗口关闭时退出。


单击它时,关闭按钮事件在代码中触发

属于该表单。您可以通过事件取消它

参数:set e.cancel = true;但是*从不这样做而不要求用户确认。
如果处理不当(即一个普通的哑巴e.cancel = true) ),它b / b
将有效地使用户无法注销或

关闭他的系统而不先通过任务杀死你的应用
$ b $经理。他们中的大多数人只需要接通电源或重置

按钮。

在任何一种情况下,你的应用都无法完全退出。



You can, but in 99% of applications you shouldn''t. It''s about
the same as mounting a brick under a car''s brake pedal to make
sure it always goes fast enough.

That X isn''t an exit button, it''s a close button (it closes a
window). Most VB applications do exit indeed when their last
window is closed.

When you click it, the "Closing" event is fired in the code
belonging to that form. You can cancel it through the event
arguments: set e.cancel = true; but *NEVER* do so without asking
the user for confirmation.

If not handled properly (i.e. a plain dumb "e.cancel=true"), it
will effectively make it impossible for a user to log off or to
shut down his system without first killing your app through task
manager. Most of them will just reach for the power or reset
button instead.
In either case, your app won''t be able to exit cleanly.


*" Agnes" < AG *** @ dynamictech.com.hk> scripsit:
* "Agnes" <ag***@dynamictech.com.hk> scripsit:
我需要在表单中禁用退出按钮。
但是,分钟。最多按钮需要保留它
I need to disable the exit button in the form .
However, the min. and max. button need to keep it




\\\

私有声明自动功能GetSystemMenu Lib" user32.dll" (_

ByVal hWnd As IntPtr,_

ByVal bRevert As Int32 _

)作为IntPtr


私有声明自动功能GetMenuItemCount Lib" user32.dll" (_

ByVal hMenu作为IntPtr _

)作为Int32

私有声明自动函数DrawMenuBar Lib" user32.dll" (_

ByVal hWnd As IntPtr _

)作为Int32

私有声明自动功能RemoveMenu Lib" user32.dll" (_

ByVal hMenu作为IntPtr,_

ByVal nPosition作为Int32,_

ByVal wFlags作为Int32 _

)作为Int32


私有Const MF_REMOVE为Int32 =& H1000


私人小组RemoveCloseButton(BYVAL frmForm如表格)

尺寸HMENU作为IntPtr的,正如的Int32

HMENU = GetSystemMenu(frmForm.Handle,0)

如果不是hMenu.Equals(IntPtr.Zero)那么

n = GetMenuItemCount(hMenu)

如果n> 0然后

RemoveMenu(HMENU中,n - 1,MF_BYPOSITION或者MF_REMOVE)

RemoveMenu(HMENU,N - 2,MF_BYPOSITION或者MF_REMOVE)

DrawMenuBar(frmForm.Handle)

结束如果

结束如果

结束子

///


-

Herfried K. Wagner [MVP]

< URL:http://dotnet.mvps.org/>



\\\
Private Declare Auto Function GetSystemMenu Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal bRevert As Int32 _
) As IntPtr

Private Declare Auto Function GetMenuItemCount Lib "user32.dll" ( _
ByVal hMenu As IntPtr _
) As Int32

Private Declare Auto Function DrawMenuBar Lib "user32.dll" ( _
ByVal hWnd As IntPtr _
) As Int32

Private Declare Auto Function RemoveMenu Lib "user32.dll" ( _
ByVal hMenu As IntPtr, _
ByVal nPosition As Int32, _
ByVal wFlags As Int32 _
) As Int32

Private Const MF_BYPOSITION As Int32 = &H400
Private Const MF_REMOVE As Int32 = &H1000

Private Sub RemoveCloseButton(ByVal frmForm As Form)
Dim hMenu As IntPtr, n As Int32
hMenu = GetSystemMenu(frmForm.Handle, 0)
If Not hMenu.Equals(IntPtr.Zero) Then
n = GetMenuItemCount(hMenu)
If n > 0 Then
RemoveMenu(hMenu, n - 1, MF_BYPOSITION Or MF_REMOVE)
RemoveMenu(hMenu, n - 2, MF_BYPOSITION Or MF_REMOVE)
DrawMenuBar(frmForm.Handle)
End If
End If
End Sub
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>


这篇关于如何禁用“退出”按钮按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆