C# - How to remove the Maximize bar, Minimize, but only keep one Close button?

Asked

Viewed 3,902 times

5

I created a graphic component and wrote a command line that removed the control bar from the graphic component, but all the buttons are gone. Is there any way to just let the Close button?

Or I’ll have what kind of component Form to another?

public Form1()
{
     InitializeComponent();
     this.StartPosition = FormStartPosition.CenterScreen;
     this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;                
}
  • Try to use: this.MaximizeBox = false;
 this.MinimizeBox = false; if successful I put as an answer

  • @Murilo-Fechio, in this case I want to create a window without the borders of the system, just with a button Close. Like the Microsoft Visual Studio window when it is installed.

2 answers

4


You have two alternatives.

  1. Disable buttons you don’t want through the Maximizebox and Minimizebox properties by assigning the False value to them.

  2. You can modify the style of the form through the Formborderstyle property as you mentioned, using the Sizabletoolwindow or Fixedtoolwindow

  • that’s what I did there in the code, but all the buttons are gone. :/

  • That’s not what you did in the code. You’re setting Formborderstyle to None. I quoted you for using Sizabletoolwindow or Fixedtoolwindow

  • Oh true, I did not see the second part of the code, I only looked at the Formborderstyle, I will try here Thiago.

  • Thiago, I saw no difference in the use of these two properties, Sizable... and Fixed...

  • Both have only the close button. By the name of the property Sizable... It seems that there would be a maximize button in the middle.

  • @Israelsousa actually both have the close button. But Sizable doesn’t mean it will enable maximizing, which means it can be resizable. Activate the sizable and go to some corner of the window and you will see that you have the possibility to increase/decrease the window. Then do the test with Fixed

  • @Israelsousa worked?

  • Thiago, the property you gave me was still embroidered on the system. kkk! None same, but your answer is correct due to form having only button close...

  • I inserted a label and put a X customized over the Form, was cool, it was really what I wanted to do. I don’t know if it was gambiarra kkkk!

  • @Israelsousa but you started the question saying that you just wanted to close the button and it really leaves the edge of the system. And now you’re saying you didn’t want the edge of the system anymore. They’re different things. But anyway, if the answer was helpful mark it please as solved.

  • True... But it was helpful yes your reply. Thank you.

Show 6 more comments

2

How to do without using code (designer mode only):

  • Open the Form1.Cs
  • click on your form and press F4 to open the properties
  • select "false" for the "Maximizebox" property"
  • select "false" for the "Minimizebox" property"
  • select "Sizable" for the "Formborderstyle" property".

With this, the buttons will remain but have no effect and your Form cannot be resized.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.