如何在devexpress winform中禁用ControlBox中的关闭按钮 [英] How to disable Close Button from ControlBox in devexpress winform

查看:140
本文介绍了如何在devexpress winform中禁用ControlBox中的关闭按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我在C#中使用devexpress winform.

如何禁用ControlBox中的关闭按钮?

在此先谢谢您.

解决方案

您可以尝试使用

Button.Enabled =假


您可以通过将窗体的ControlBox属性设置为False来完全隐藏控制面板上的关闭按钮.

或者我禁用它的一种方法是拥有一个布尔变量,我最初将其设置为False.然后,每次用我自己的按钮关闭表单时,我都将其设置为True.这样,如果用户单击关闭按钮,而我的变量仍为False,则我知道他们在控制框中使用了关闭按钮.然后,您要做的就是将代码添加到FormClosing事件中,以在该变量仍为false时取消该事件.

这是一些我执行类似操作的示例代码.当用户同步由名为boolIsSyncRunning的变量跟踪的应用程序时,我禁用了关闭按钮:

 私有  Sub  Update_FormClosing( ByVal 发​​件人 As  对象 ByVal  e  As  System.Windows.Forms.FormClosingEventArgs)句柄  .FormClosing
    如果 boolIsSyncRunning 然后
        ' 在同步运行时,请勿让用户关闭窗口
        My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Beep)
        e.Cancel = 真实
    结束 如果
结束  



希望这会有所帮助.


Hi all of you,


I am using devexpress winform in c#.

How can I disable the close button from ControlBox?

Thanks in advance.

解决方案

You can try using

Button.Enabled = false

where the Button is the control in question.


You can completely hide the close button on the control panel by setting the form''s ControlBox property to False.

Or one way that I''ve disabled it is to have a boolean variable that I set initially to False. Then every time the form is closed by a button of my own I set it to True. That way, if the user clicks the close button and my variable is still False, I know they used the close button in the control box. Then all you have to do is add code to the FormClosing Event to cancel the event if the variable is still false.

Here is some sample code where I do something similar. I am disabling the close button when the user is synchronizing the application which is tracked by a variable called boolIsSyncRunning:

Private Sub Update_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    If boolIsSyncRunning Then
        'Do not let user close window while synchronize is running
        My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Beep)
        e.Cancel = True
    End If
End Sub



Hope this helps.


这篇关于如何在devexpress winform中禁用ControlBox中的关闭按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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