I want a simple way to maximize and normal windowstate all in one button (click me for image)
Method (code) c# coding -
int maxornot;
private void MaxButton_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Maximized;
maxornot = 1;
if (WindowState == FormWindowState.Minimized);
{
maxornot = 0;
}
if (maxornot == 0);
{
}
}
if this method is pointless and there is a way to simplify the code then leave a code below.
p.s i didn't put much thought into how to get this method to work cause im just having headaches :P
From what you already showed in your code-example you want a button to Switch from
FormWindowState.NormaltoFormWindowState.Maximizedand the other way as well.Now instead of Setting the
FormWindowStateof your form to Maximized at the start of your click Even you should first check the current state of your Window:FormWindowState has 3 different states:
Normal,MinimizedandMaximized. In your case you don't needMinimized. All you have to do now is Switch between normal and maximized in your method depending on what is current active:This 4 rows of code are all you need in the click event method.
This simple
if-elsemay also be converted to a ternary: