Visually remove/disable close button from title bar .NET

前端 未结 13 947
后悔当初
后悔当初 2020-12-03 21:51

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

13条回答
  •  离开以前
    2020-12-03 22:27

    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.

提交回复
热议问题