How to remove/disable the form's close (X) button?

  • Thread starter Thread starter ohadasor
  • Start date Start date
O

ohadasor

Hello,

I have an MDI child, which I need to be opened as long as the mainframe
is opened. The problem is that the user can close it using the X button
in the form's top-right edge.

How can I make this button disappear, or at least disabled?

I'm using C# with .NET Framework 2.0.

Thanks a lot!
 
Just off the top of my head....

Override the WndProc so that you can trap the WM_NCHITTEST and WM_NCPAINT
messages.

Paint your own title bar without the close button in the handler for
WM_NCPAINT

Prevent the detection of the close button in the WM_NCHITTEST.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
If you don't need the other icons from control box (minimize, maximize), you
can set the ControlBox property to false.
You can also override the Closing event of your form and cancel it (look at
closing reason and set e.Cancel = true;), which will not disable or let
disappear the button, but will not let anyone to close the form.
 
Back
Top