Application Settings and Form Location & Size

R

Roger Down

I'm trying to use Application Settings with From Location & Size. I have
created the property binding from the Designer in Visual Studio.

ClientSize = MainFormClientSize
Location = MainFormLocation

I also have the following code:

private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
Properties.Settings.Default.MainFormClientSize = this.ClientSize;
Properties.Settings.Default.MainFormLocation = this.Location;
Properties.Settings.Default.Save();
}

The code seems to work fine. I can start the application, change the size
and location and close the application. And the next time I open the
application, the size and location is correct from the last time the
application was closed.

But something strange happens if I try to minimize and restore the
application. If I already have a size and location saved, do a minimize and
restore, then the initial default value are set on the form.

Do I need additional code to addresse minimize / restore scenarioes ?

Best of regards... :)
 
H

Herfried K. Wagner [MVP]

Roger Down said:
I'm trying to use Application Settings with From Location & Size. I have
created the property binding from the Designer in Visual Studio.

ClientSize = MainFormClientSize
Location = MainFormLocation

I also have the following code:

private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
Properties.Settings.Default.MainFormClientSize = this.ClientSize;
Properties.Settings.Default.MainFormLocation = this.Location;
Properties.Settings.Default.Save();
}

The code seems to work fine. I can start the application, change the size
and location and close the application. And the next time I open the
application, the size and location is correct from the last time the
application was closed.

You may want to take a look at the form's 'RestoreBounds' property.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top