c# disable application - Windows Forms: How to hide Close (x) button?





4 Answers

We can hide close button on form by setting this.ControlBox=false;

enable wpf cp_noclose_button

I have a modal dialog, and need to hide the Close (X) button, but I cannot use ControlBox = false, because I need to keep the Minimize and Maximize buttons.

I need to hide just Close button, is there any way to do that?

Thanks a lot!

Update: I had permission to disable it, which is simpler :) Thanks all!




If you really want to hide it, as in "not visible", then you will probably have to create a borderless form and draw the caption components yourself. VisualStyles library has the Windows Elements available. You would also have to add back in the functionality of re-sizing the form or moving the form by grabbing the caption bar. Not to mention the system menu in the corner.

In most cases, it's hard to justify having the "close" button not available, especially when you want a modal form with minimizing capabilities. Minimizing a modal form really makes no sense.




In your form's properties set 'Control Box' = False but it will hide Minimized and Maximize as well.




if this is an option you can set

 this.FormBorderStyle = FormBorderStyle.None;

then recreate the minimize and maximize buttons

    private void button1_Click(object sender, EventArgs e)
    {
        this.WindowState = FormWindowState.Maximized;
    }

    private void button2_Click(object sender, EventArgs e)
    {
        this.WindowState = FormWindowState.Minimized;
    }



Related


Tags

c#   winforms