views:

573

answers:

4

I have been asked to remove or disable the close button from our VB .NET 2005 MDI application. There are no native properties on a form that allow you to grey out the close button so the user cannot close it, and I do not remember seeing anything in the form class that will allow me to do this.

Is there perhaps an API call or some magical property to set or function to call in .NET 2005 or later to do this?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~

More information:

I need to maintain the minimize/maximize functionality

I need to maintain the original title bar because the form's drawing methods are already very complex.

+1  A: 

You should be able to override the OnClose event of the form. This is common when an application minimizes to the System Tray when "closed".

Dave Swersky
+1  A: 

You can set the ControlBox property to false, but the whole "title bar" will be gone...

jonaspp
+7  A: 
Philip Wallace
I thought of this as well. Sadly, I forgot to specify but I need the minimize/maximize functionality. I could do these programatically, but I would need to add essentially my own toolbar with the minimize and maximize buttons on it.
Jrud
I added to the bottom of my answer.
Philip Wallace
Perfect! this works like a charm. Thanks!
Jrud
+4  A: 

You can disable the close button and the close menu item in the system menu by changing the "class style" of the window. Add the following code to your form:

const int CS_NOCLOSE = 0x200;

protected override CreateParams CreateParams {
    get {
        CreateParams cp = base.CreateParams;
        cp.ClassStyle |= CS_NOCLOSE;
        return cp;
    }
}

This will not just stop the window from getting closed, but it will actually grey out the button. It is C# but I think it should be easy to translate it to VB.

jdm