Monday, September 18, 2006

Removing the close box from a c# form

I have a child of a MDI container and I don't want the user to be able to close it, or maximize, or minimize it. But I do want the user to be able to resize it and drag it around and will. So I want to get rid of the close, minimize and maximize buttons but retain the blue strip.

If you write some code like so:


this.ControlBox = false;
this.MaximizeBox = false;
this.MinimizeBox = false;


Where "this" is some form, you may find yourself with a control lacking a blue strip to move the form around! The solution to this problem is to enter some text in the text field.


this.Text = "My useful form";
this.ControlBox = false;
this.MaximizeBox = false;
this.MinimizeBox = false;


And that seems to be how it's done. Of course there are other ways override the message handler or using PInvoke (yes I tried Google before working this out for myself) but you really don't need to.
Post a Comment