Disabling the Close-Button temporarily

后端 未结 7 1159
后悔当初
后悔当初 2020-12-31 14:45

I need to disable just the close button (minimize and maximize should be allowed) temporarily.

Every solution I\'ve tried disables all the buttons

7条回答
  •  既然无缘
    2020-12-31 15:05

    You can't hide it, but you can disable it:

    private const int CP_NOCLOSE_BUTTON = 0x200;
    protected override CreateParams CreateParams
    {
        get
        {
           CreateParams myCp = base.CreateParams;
           myCp.ClassStyle = myCp.ClassStyle | CP_NOCLOSE_BUTTON ;
           return myCp;
        }
    }
    

    Source: http://www.codeproject.com/Articles/20379/Disabling-Close-Button-on-Forms

    If you absolutely need to hide it, the only way to do it is to create a borderless form, then draw your own minimize and maximize buttons. Here is an article on how to do this: http://www.codeproject.com/Articles/42223/Easy-Customize-Title-Bar

    Before considering either of these solutions, you should maybe rethink why you need to do this. Depending on what you are trying to do, there is probably a much better way to present the UI to the user other than taking away the familiar 'X' close button.

提交回复
热议问题