By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,110 Members | 1,541 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,110 IT Pros & Developers. It's quick & easy.

Anyone have a HOWTO on this requirement?

P: n/a
Hi,

I would like to specify a group of Properties/Fields of some objects on a
WinForm, for which I would like to have the values loaded from the Registry,
and saved to it upon closing of the form.

ie. the form's Size, the positions and sizes of some controls on that form
should "remember" their state across the sessions of a user.

I thought a Hashtable would be a good idea to set the name of the
registry-entry as the Key name of the HT-entry, and the key-value would be
the value of the property/field.

but if I do this:
myHT.add("Form_Size", this.Size);
of course only the current-value of the size would be saved - or better, if
I changed the value in the hashtable to another size, the Form.Size would
not get updated. Are delegates suitable for properties/fields, or do I have
to do it another way? There must be a way to accomplish this!

Thanks for any input on this!

regards, Tilli
Nov 16 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hi,

You could also use a XML file local to your application. If you for some
reason want to use the HashTable you can serialize it with no big problem I
think.
It will be your code responsability to assign/update the values when the
form is created/closed though.
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Tilfried Weissenberger" <ti***@weissenberger.at> wrote in message
news:10***************@news.aic.at...
Hi,

I would like to specify a group of Properties/Fields of some objects on a
WinForm, for which I would like to have the values loaded from the Registry, and saved to it upon closing of the form.

ie. the form's Size, the positions and sizes of some controls on that form
should "remember" their state across the sessions of a user.

I thought a Hashtable would be a good idea to set the name of the
registry-entry as the Key name of the HT-entry, and the key-value would be
the value of the property/field.

but if I do this:
myHT.add("Form_Size", this.Size);
of course only the current-value of the size would be saved - or better, if I changed the value in the hashtable to another size, the Form.Size would
not get updated. Are delegates suitable for properties/fields, or do I have to do it another way? There must be a way to accomplish this!

Thanks for any input on this!

regards, Tilli

Nov 16 '05 #2

P: n/a
Create two methods
i.e.
SavePosition , RestorePosition

Call SavePosition when the form closes (OnClose) and call the
RestorePosition when the form loads...

In SavePosition use the RegistryKey class to create/check for the existance
of your custom key and simply store the X, Y, Heihght, Width as 4 key value
pairs to that entry. Then in the RestorePosition again open the key if it
exists and load those 4 values. You can name them any way you like. Set
your Forms size and position and your done

JIM
"Tilfried Weissenberger" <ti***@weissenberger.at> wrote in message
news:10***************@news.aic.at...
Hi,

I would like to specify a group of Properties/Fields of some objects on a
WinForm, for which I would like to have the values loaded from the Registry, and saved to it upon closing of the form.

ie. the form's Size, the positions and sizes of some controls on that form
should "remember" their state across the sessions of a user.

I thought a Hashtable would be a good idea to set the name of the
registry-entry as the Key name of the HT-entry, and the key-value would be
the value of the property/field.

but if I do this:
myHT.add("Form_Size", this.Size);
of course only the current-value of the size would be saved - or better, if I changed the value in the hashtable to another size, the Form.Size would
not get updated. Are delegates suitable for properties/fields, or do I have to do it another way? There must be a way to accomplish this!

Thanks for any input on this!

regards, Tilli

Nov 16 '05 #3

P: n/a
One other thing I should mention though is that you might want to check
first to see if the form is Maximized before saving its size, becuase you
probably do not want to restore a froms size to the max window size becuase
it confuses users. Usually I test for this and if it is maxed I set it to
some smaller size like 800x600 or some such size.

JIM
"james" <no****@hypercon.net> wrote in message
news:uL**************@TK2MSFTNGP09.phx.gbl...
Create two methods
i.e.
SavePosition , RestorePosition

Call SavePosition when the form closes (OnClose) and call the
RestorePosition when the form loads...

In SavePosition use the RegistryKey class to create/check for the existance of your custom key and simply store the X, Y, Heihght, Width as 4 key value pairs to that entry. Then in the RestorePosition again open the key if it
exists and load those 4 values. You can name them any way you like. Set
your Forms size and position and your done

JIM
"Tilfried Weissenberger" <ti***@weissenberger.at> wrote in message
news:10***************@news.aic.at...
Hi,

I would like to specify a group of Properties/Fields of some objects on a WinForm, for which I would like to have the values loaded from the

Registry,
and saved to it upon closing of the form.

ie. the form's Size, the positions and sizes of some controls on that form should "remember" their state across the sessions of a user.

I thought a Hashtable would be a good idea to set the name of the
registry-entry as the Key name of the HT-entry, and the key-value would be the value of the property/field.

but if I do this:
myHT.add("Form_Size", this.Size);
of course only the current-value of the size would be saved - or better,

if
I changed the value in the hashtable to another size, the Form.Size would not get updated. Are delegates suitable for properties/fields, or do I

have
to do it another way? There must be a way to accomplish this!

Thanks for any input on this!

regards, Tilli


Nov 16 '05 #4

P: n/a
Thanks all for your responses.

Unfortunately my example of the size/position is just for demonstration
purpose. I inherit from a common form, which does that for me already. I
just want to be able to add more attributes, such as column-width of grids,
width of dynamically positioned sliders etc. - I want to be able to pass a
list of objects/properties to a function which will then either save the
state to the registry (that's the easy part), or load it from there back
into the properties (that's where I have the problem)!

so it's not a conventional solution I require - I guess I have to use
Reflection to do what I want - someone out there must know how this can be
accomplished!

Thanks for any further input!

regards, Tilli
Nov 16 '05 #5

P: n/a
You can just manually save and load the properties of the controls you want
to save. Reflection isn't going to help you if you dont know what you are
storing because you may attempt to store things you dont need to store and
re-storing them might cause issues if done in an incorrect order. Basically
what I would do is create an interface like IRestorable or some such and
then subclass all the controls you want to be able to restore, and implement
that interface in the control. Then your form can just go through all its
controls and call the store/restore method. Each control should know then
what it needs to do and how it needs to do it.

By the way, I use DevExpress's tools which can all store/restore themselves
JIM
"Tilfried Weissenberger" <ti***@weissenberger.at> wrote in message
news:10***************@news.aic.at...
Thanks all for your responses.

Unfortunately my example of the size/position is just for demonstration
purpose. I inherit from a common form, which does that for me already. I
just want to be able to add more attributes, such as column-width of grids, width of dynamically positioned sliders etc. - I want to be able to pass a
list of objects/properties to a function which will then either save the
state to the registry (that's the easy part), or load it from there back
into the properties (that's where I have the problem)!

so it's not a conventional solution I require - I guess I have to use
Reflection to do what I want - someone out there must know how this can be
accomplished!

Thanks for any further input!

regards, Tilli

Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.