German Wear Discount Shop - Click Here Write for Dotnet-friends and earn for your each submission [Dot]Net-Friends
Skip Navigation Links
Home
Latest
Fast Code
Articles
Tutorials
Online Resources
Forums
Login   | Hi, Guest


Disable Close button in Windows Form
Written By santhosh Kapa On 16/05/2008

This article shows how to change the default behaviour of the form. Here this small tip make form's close button disabled.

Views: 599
Rating: 5
Login to Rate
s2a2n2
Tagged Under: GDI, General, Language Specifications, Visual Studio 2008 Tips and Tricks

Explanation:

Sometimes, in our applications we require to show the form and prevent user from closing it for some work still need to be done. In that case, we can disable the close button of the form. The following is a simple tip how to go about this. Before jumping to the coding stuff just consider the following write up on how to go about this..

During the creation of the Form object, in the default constructor, .Net would use the default creation parameters available in base class CreateParams property. In fact, CreateParams property is available in Forms.Control class. In our form class (which is derived from System.Windows.Forms.Form) override this property and modify the creation flags. For disabling the Close button use 0x200 to modify the ClassStyle member of the CreateParams.


private const int DISABLE_CLOSE_BUTTON = 0x200;
protected override CreateParams CreateParams
{
     get
           {
                 CreateParams myCp = base.CreateParams;
                 myCp.ClassStyle = myCp.ClassStyle | DISABLE_CLOSE_BUTTON ;
                 return myCp;
            }
}
Delicious Digg reddit reddit Technorati
About the Author:

@@ I am working as Software Engineer and well versed in .Net Technologies, Javascript, XML, Web Services, CSS and little bit of other technologies too. I like to work hard for achieving and meet targets and believe in the hard work. Cheers!
Check santhosh Kapa Profile

Related Useful Links:
Visitors/Readers Comments
(for questions please use The Forum)



sri
Good tip! cheers

18/05/2008 00:11:01 UTC

Pratik
Good tip adn simple to do, thanks!

18/05/2008 23:10:33 UTC

mahi
its a cool stuff.Nice one ....

07/06/2008 04:23:52 UTC

biju
it`s really great. thanks fro the help.

29/08/2008 18:58:19 UTC




Add your Comments

Name:  
Message:
Note: For faster response please use Forums >> for your questions instead of the comments area! (Admin)