 |
|
 |
Hi,
Thanks for such handy information. It helps me.
Keep it up !
Thanks
|
|
|
|
 |
|
|
 |
|
 |
More the size of a tip, rather than an article, still not bad.
Just because the code works, it doesn't mean that it is good code.
|
|
|
|
 |
|
 |
I can't figure out how to enable it again.
Or how to alternatively close the form.
Also, I wondered how to use this on a MessageBox?
Please help! I'm a n00b at .NET!
|
|
|
|
 |
|
 |
thanks for sharing, simple and useful.
|
|
|
|
 |
|
|
 |
|
 |
Better impossible - Thanks
Joao Pedro
|
|
|
|
 |
|
|
 |
|
 |
thanks man works just perfectly
|
|
|
|
 |
|
|
 |
|
 |
a big thanks. - to Abhishek Sur
|
|
|
|
 |
|
 |
This thing very helped me...
Thanks
|
|
|
|
 |
|
 |
Hai,
Simple and great Article. I don't want to disable the close button from the Form. Instead I want it to call a function, asking the confirmation from the user. If he clicks,
Yes - Form should be closed.
No - No Action.
How can we achieve this?
Happy Coding Guys.....
Regards,
Nagendran
|
|
|
|
 |
|
 |
Use the MessageBox.Show() function to get the user response.
if(DialogResult.OK == MessageBox.Show())
{
//close the form
}
else
{
//do something
}
To handle the Close button, use the code.
this.Closing += new System.ComponentModel.CancelEventHandler(this.YourForm_Closing);
Add the above line in the InitializeComponent() function and handle that function according to your requirement for the YourForm.
|
|
|
|
 |
|
 |
Thanks to the author of this great article. The close button is now disabled but still shows up on the form as a grayed-out control. Just to save some confusion for the end-user, I want a tooltip for close button that tells the user how to exit the application (my app can only be closed from the task bar icon). How do I set a tooltip for this disabled 'close button'?
Thanks in advance!
|
|
|
|
 |
|
|
 |
|
 |
Soo simple!!
Hello!
|
|
|
|
 |
|
 |
1)Changing the behaviour of forms is not a standard solution, removing the close button is just a gimmick, user can still sue Alt+F4 to close the form.
2)Understand the problem. The problem was not to remove the close button but how to ensure some action has taken place before allwoing the form to be closed, here is one way to check some conditions have been satisfied before allowing the form to close and informing the user why they can not close the form instead of leaving the user wondering why the can't close the form.
http://msdn2.microsoft.com/en-us/library/system.windows.forms.form.closing.aspx[^]
Read The Manual before consulting your team!
Regards
|
|
|
|
 |
|
 |
1) You can prevent the form to close by adding e.Cancel = true; in the FormClosing event.
2) There are special situation where the problem is not "ensure that some action...".
Don't see bad things where there are not !
Regards.
Steph.
|
|
|
|
 |
|
 |
>1) You can prevent the form to close by adding e.Cancel = true; in the FormClosing event.
That is what the documenation says and that is the link I sent.
>2) There are special situation where the problem is not "ensure that some action...".
Maybe, but in this case the approach was wrong.
>Don't see bad things where there are not !
Bad? What bad things? Bad and wrong are not the same thing. Just wante to point out the standard solution is simplere.
Ok maybe I should have not said wrong solution, but there are more standard ways to do this.
Pointing out better ways is not seeing bad in things but trying to make things better.
Kind Regards.
Arjang
|
|
|
|
 |
|
 |
on second thought, this method in iteslf is intresting, maybe mix it up with some more code and becomes a nice visual effect for when they can see that they can close the form.
it is the correct solution to the topic : "Disabling Close button on Forms".
I dont know why I thought it was a method to prevent the user from closing the window.
My mistake!
Kind Regards
Arjang
|
|
|
|
 |
|
 |
To re-enable it, just save the original myCp.ClassStyle to a global variable and reset it when you want to re-enable the close button!
|
|
|
|
 |
|
 |
I try it, but not success.
|
|
|
|
 |
|
 |
I guess there isn"t a way to change it after design time. It is read only.
|
|
|
|
 |
|
 |
You can simply make the change conditional. I set my new flag, bCloseAvailable, based on a configuration setting:
private const int CP_NOCLOSE_BUTTON = 0x200;
protected override CreateParams CreateParams
{
get
{
CreateParams myCp = base.CreateParams;
if (!bCloseAvailable)
myCp.ClassStyle = myCp.ClassStyle | CP_NOCLOSE_BUTTON;
return myCp;
}
}
|
|
|
|
 |