Saving windows size and position?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there an automatic way to tell a windows to save its size
and position, or do I have to save these parameters to the
registry when the form quits and then reload them next time?
 
Is there an automatic way to tell a windows to save its size
and position, or do I have to save these parameters to the
registry when the form quits and then reload them next time?

AFAIK, you have to do this yourself. I simply created my own component
control that does all this for me. Then I just reference it's dll and
add it to any form that I want to persist these settings.

Thanks,

Seth Rowe
 
AFAIK, you have to do this yourself. I simply created my own component
control that does all this for me. Then I just reference it's dll and
add it to any form that I want to persist these settings.

Couldn't you just add some code the the application's main form's
FormClosing event to update the project Settings to specify the
current window size and position, and also put code in the main form's
Activate event to set the window's size and position from the values
in the project Settings?
 
Couldn't you just add some code the the application's main form's
FormClosing event to update the project Settings to specify the
current window size and position, and also put code in the main form's
Activate event to set the window's size and position from the values
in the project Settings?

The component I wrote hooks the load and formclosing events of the
host form and performs the appropriate actions. Instead of writing the
code in each project I needed the functionality I just wrapped it in
it's own class. You just have to add it and set a few properties,
(such as whether to use the registry or an xml file, etc) and you can
forget about it.

Thanks,

Seth Rowe
 
The component I wrote hooks the load and formclosing events of the
host form and performs the appropriate actions. Instead of writing the
code in each project I needed the functionality I just wrapped it in
it's own class. You just have to add it and set a few properties,
(such as whether to use the registry or an xml file, etc) and you can
forget about it.

Writing such an interface that provides overriding event handlers for
default event handlers in the main application's form is something I
have never done before. I use MSDN help a lot to figure how to do new
things, but I am not sure what keyword(s) would point me to
documentation that shows how to do that. Can you offer any? Or even
better a link?
 
Writing such an interface that provides overriding event handlers for
default event handlers in the main application's form is something I
have never done before. I use MSDN help a lot to figure how to do new
things, but I am not sure what keyword(s) would point me to
documentation that shows how to do that. Can you offer any? Or even
better a link?


Hmm... I think I explained something wrong. In the components
constructor (I think) I simply used AddHandler to wire up an event
handler for the events in the parent form of the Component.
Unfortunately, I'm off for the weekend, and don't have the code with
me - and I can't figure out how I found the parent of a component.
I'll let you know whenever I figure it out or get my source code from
work.

Thanks,

Seth Rowe
 
Is there an automatic way to tell a windows to save its size
and position, or do I have to save these parameters to the
registry when the form quits and then reload them next time?

You can easily do this with appname.exe.config where you can read the
settings for a control's font, size and a form too with
System.ConfigurationManager to read and write the settings to/from
appname.exe.config. There is a section in the Application Block download
with documentation and code examples of how to do this in VB and C#.net for
1.0 and 2.0 Frameworks.

It's a piece of cake using System.ConfigurationManager in 2.0 or
System.Configuration.ConfigurationSettings in 1.0 to do what you're wanting
to do, which you can access to get the settings at form_load and sane the
settings at form_unload events.
 
Back
Top