saving Form.ClientSize in settings

T

Tsahi Asher

hi,
i was trying to save the window size of my app using the generated
Settings class of Visual C# 2005 Express. for some reason, the stored
size was bigger from the actual size, so each time i start the app, it's
bigger than before, until it fills the screen (1024*768). the odd thing
is, that it works just fine in the IDE, and if i install it on a
different computer, and even if i use the executable produced by the IDE
instead of the one deployed by the MSI file compiled by the deployment
project.

since i have the Express edition at home, i took the app project to
work, and added a deployment project to the solution there, with a Team
Suite edition. then i ran the MSI on the work machine, and it worked
just fine (with higher resolution). when i took the MSI back home and
installed it, i received the symptom i described.

as mentioned in the subject, the actual value saved was that of the
form's ClientSize property. in the debugger, it seems like the expected
size is loaded, and then saved correctly. only outside the IDE it acts
weird.

i don't know how important that is, but this is an upgrade from a
previous version. the machine at work didn't have the previous version,
which was based on .NET 1.1. my home machine did, and this version,
based on .NET 2.0, seems to have upgraded it cleanly, except for that
problem.

here's some code:
in the form's constructor:

ClientSize = Settings.Default.ClientSize;

in a method called from the OnFormClosing() override:

Settings.Default.ClientSize = ClientSize;
Settings.Default.Save();

Tsahi
 
J

Jesse Houwing

* Tsahi Asher wrote, On 29-7-2007 23:39:
hi,
i was trying to save the window size of my app using the generated
Settings class of Visual C# 2005 Express. for some reason, the stored
size was bigger from the actual size, so each time i start the app, it's
bigger than before, until it fills the screen (1024*768). the odd thing
is, that it works just fine in the IDE, and if i install it on a
different computer, and even if i use the executable produced by the IDE
instead of the one deployed by the MSI file compiled by the deployment
project.

since i have the Express edition at home, i took the app project to
work, and added a deployment project to the solution there, with a Team
Suite edition. then i ran the MSI on the work machine, and it worked
just fine (with higher resolution). when i took the MSI back home and
installed it, i received the symptom i described.

as mentioned in the subject, the actual value saved was that of the
form's ClientSize property. in the debugger, it seems like the expected
size is loaded, and then saved correctly. only outside the IDE it acts
weird.

i don't know how important that is, but this is an upgrade from a
previous version. the machine at work didn't have the previous version,
which was based on .NET 1.1. my home machine did, and this version,
based on .NET 2.0, seems to have upgraded it cleanly, except for that
problem.

here's some code:
in the form's constructor:

ClientSize = Settings.Default.ClientSize;

in a method called from the OnFormClosing() override:

Settings.Default.ClientSize = ClientSize;
Settings.Default.Save();

My guess is that you have to set the ClientSize in the Form.Show event,
or after the InitializeComponent in the Form.Load event has run. The
constructor is too early in the forms lifecycle. Otherwise it'll just
get overridden.

Jesse
 
T

Tsahi Asher

öéèåè Jesse Houwing:
* Tsahi Asher wrote, On 29-7-2007 23:39:

My guess is that you have to set the ClientSize in the Form.Show event,
or after the InitializeComponent in the Form.Load event has run. The
constructor is too early in the forms lifecycle. Otherwise it'll just
get overridden.

Jesse
thanks, getting that at the OnLoad event override fixed the problem.

tsahi
 
J

Jesse Houwing

* Tsahi Asher wrote, On 30-7-2007 22:51:
öéèåè Jesse Houwing:
thanks, getting that at the OnLoad event override fixed the problem.

tsahi

You're welcome.

Jesse
 

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