Introduction
Sometimes we need to save some properties. This class makes that possible.
The screen shot above is just a simple example. You can easily use this class for more complex applications.
The logic is as follows:
- Determines the given named property is correct
- Determines if property return value type is
enum
- If it is an
enum, combines it with an integer (so int value type is serializable)
- If not, determines if it is a serializable, if
false, stops executing for current property
- When your host object (must be a form) is loaded, it checks the registry stream, then sets the properties
- When the host is closed, it saves the properties to registry
Using the Code
public Form1()
{
InitializeComponent();
TolgahanFormPropertySaver svr = new TolgahanFormPropertySaver
(this,"WindowState","Size","Location");
svr.AddChild(radioButton1,"Checked");
svr.AddChild(radioButton2,"Checked","Enabled","Visible");
svr.AddChild(radioButton3,"Checked");
svr.AddChild(checkBox1,"Checked");
svr.AddChild(textBox1,"Text");
}
TolgahanFormPropertySaver Class Diagram
Why I Wrote This?
When I was developing an app, it was so difficult to give names, convert types and save with different keys and read the same key with the same things... So I tried to manage all property values from one point. That is the reason I wrote this.
Which Property Types Could Be Used
This class allows only the properties which have ENUM TYPE return values (like FormWindowState, View, Dock, ... etc.), Serializable Struct return values (like Size, Point, .. etc.), Serializable types (like int16, int32, int64, float, bool, string... double, decimal.. etc), Serializable classes (like TreeNode, ListViewItem... etc) and Serializable custom classes (which imported ISerializable interface).
Known Bugs
I still don't know.:) So, if you find any bugs, please report them to me.
Happy coding!
History
- 15th September, 2007: Initial post