Steve asks:
I figured out how to set the background, foreground etc to the user setting config file but I am having trouble saving the opened children widows on closing to the settings. Is it approprate to save this info to the user setting config file?
I create a new setting of type String Collection but at start-up when reading the user setting file it is extreamly slow. Would I be better off in the registry.
Youssef's Reply:
Steve, you have several choices but I believe you may be making it more difficult that it needs to be. Putting some configuration in an xml/config file and the rest in the settings file is not acceptable. The Settings even though may seem straight forward is not the right place and will most likely cause you more grief than it's worth.
The choices you had are:
1- Simplest:
1a- Make a UserPreferences class that conatins all the persistent information (WaveBackColor, WaveForeColor, WaveThickness, FileViewFont, etc., and what you need is a StringCollection (like a List) for the open document files and you need a Rectangle which represents the Main Window dimensions and location).
1b- Build a UserPreferencesMgr static class that contains a single static member of type UserPreferences.
1c- When the user changes a color, font, thickness, etc, Simply use the UserPreferencesMgr to set those values into the fields of the UserPreferences class.
1d- Once you have that, all you need to do is Within the Main Form's Closing event, set the Window Rectangle in UserPreferences to that of your main Form Window and the list of Open MDI Child wave files.
1e- Within the Main Form's Closing event Then Serialize that UserPreferences class using SoapFormatter (SOAP = XML, ugly XML but XML nonetheless). This is the easiest choice.
2- A bit more Complex but cleaner:
2a- Same as 1a-1d.
2b- But instead of serializing the UserPreferences using SOA, write the values of each of the fields one by one to an XML file using an XmlWriter class or one of its cousins (See FileIO slides)
I just took the final project source I have and spent 15 minutes and switched from registry to an xml file using approach #1 above. I have uploaded the sample(version 1.0.0.7) and XML file.
Hope this helps
I figured out how to set the background, foreground etc to the user setting config file but I am having trouble saving the opened children widows on closing to the settings. Is it approprate to save this info to the user setting config file?
I create a new setting of type String Collection but at start-up when reading the user setting file it is extreamly slow. Would I be better off in the registry.
Youssef's Reply:
Steve, you have several choices but I believe you may be making it more difficult that it needs to be. Putting some configuration in an xml/config file and the rest in the settings file is not acceptable. The Settings even though may seem straight forward is not the right place and will most likely cause you more grief than it's worth.
The choices you had are:
1- Simplest:
1a- Make a UserPreferences class that conatins all the persistent information (WaveBackColor, WaveForeColor, WaveThickness, FileViewFont, etc., and what you need is a StringCollection (like a List) for the open document files and you need a Rectangle which represents the Main Window dimensions and location).
1b- Build a UserPreferencesMgr static class that contains a single static member of type UserPreferences.
1c- When the user changes a color, font, thickness, etc, Simply use the UserPreferencesMgr to set those values into the fields of the UserPreferences class.
1d- Once you have that, all you need to do is Within the Main Form's Closing event, set the Window Rectangle in UserPreferences to that of your main Form Window and the list of Open MDI Child wave files.
1e- Within the Main Form's Closing event Then Serialize that UserPreferences class using SoapFormatter (SOAP = XML, ugly XML but XML nonetheless). This is the easiest choice.
2- A bit more Complex but cleaner:
2a- Same as 1a-1d.
2b- But instead of serializing the UserPreferences using SOA, write the values of each of the fields one by one to an XML file using an XmlWriter class or one of its cousins (See FileIO slides)
I just took the final project source I have and spent 15 minutes and switched from registry to an xml file using approach #1 above. I have uploaded the sample(version 1.0.0.7) and XML file.
Hope this helps
Note that if you are using SoapFormatter, this formatter has a bug that has been (by design) outstanding for 5 years, and when I contacted Microsoft about it 5 years ago they said, they are not going to fix because SoapFormatter will no longer be supported moving forward. So SoapFOrmatter does not know how to serialize any Generic type like List for example. So instead you can use StringCollection.
ReplyDelete