If you add this code to your FormClosing
event handler:
if (WindowState == FormWindowState.Maximized)
{
Properties.Settings.Default.Location = RestoreBounds.Location;
Properties.Settings.Default.Size = RestoreBounds.Size;
Properties.Settings.Default.Maximised = true;
}
else
{
Properties.Settings.Default.Location = Location;
Properties.Settings.Default.Size = Size;
Properties.Settings.Default.Maximised = false;
}
Properties.Settings.Default.Save();
It will save the current state.
Then add this code to your constructor:
if (Properties.Settings.Default.Maximised)
{
WindowState = FormWindowState.Maximized;
Location = Properties.Settings.Default.Location;
Size = Properties.Settings.Default.Size;
}
else
{
Location = Properties.Settings.Default.Location;
Size = Properties.Settings.Default.Size;
}
It will restore the last state.
It even remembers which monitor in a multi monitor set up the application was maximised to.