Click here to Skip to main content
16,012,821 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all of you,


I am using devexpress winform in c#.

How can I disable the close button from ControlBox?

Thanks in advance.
Posted

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:
VB
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.
 
Share this answer
 
Comments
deepakjagd 5-Oct-11 11:34am    
Actually I used devexpress tool. Therefore this code is not supported.

In my application I am using notifyicon, when i closed my application using close button (ControlBox) only the main form is closed. The .exe of application still runing. I want to close whole application. Thats why I want disable this button from main form.
Kschuler 5-Oct-11 11:47am    
Sorry. I assumed it was still a typical windows form object and you just incorporated DevExpress components on it. I've never used DevExpress, so I guess I can't help you. Sorry again.
You can try using

Button.Enabled = false

where the Button is the control in question.
 
Share this answer
 
Comments
deepakjagd 5-Oct-11 8:15am    
Thanks,

But its not only a Button. It is Close Button which is in the top of the form near minimize, Maximize button.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900