How to save the Windows current view and reload when next time the application is started?
-
Hi, I am writing code to reload the last active items and windows of the application, Basically I have 4 windows 2 are datagridview , 1. listview, 1 is tree view, in these 4 windows I can able add data from different files based on user selection. I need to reload all this when the application is restarted. currrently I am writing manually all data into the file and saved the file path location in windows registry, I felt it is very time consuming, and don't now how to improve the timimg, please provide your inputs is there a way to do this job in a simple manner. :)
SomaShekhar
-
Hi, I am writing code to reload the last active items and windows of the application, Basically I have 4 windows 2 are datagridview , 1. listview, 1 is tree view, in these 4 windows I can able add data from different files based on user selection. I need to reload all this when the application is restarted. currrently I am writing manually all data into the file and saved the file path location in windows registry, I felt it is very time consuming, and don't now how to improve the timimg, please provide your inputs is there a way to do this job in a simple manner. :)
SomaShekhar
It sounds to me that you're on the right track. Saving state is really never easy. What I have done is created a UserPreference class for my apps. This is simply a class the encapsulates a the Dictionary<> object, which is new to .Net 2.0 What I do is init the dictionary like this: C#: Dictionary<string,> preference = new Dictionary<string,>; With the "preference" object, you can specify a unique string for the key and use it to store and retrieve as many items as necessary to restore the program state. This code model is not as messy but you will always have to do some "manual labor"! Cheers, Richard
I've used up all my sick days, so today I'm calling in dead.
-
It sounds to me that you're on the right track. Saving state is really never easy. What I have done is created a UserPreference class for my apps. This is simply a class the encapsulates a the Dictionary<> object, which is new to .Net 2.0 What I do is init the dictionary like this: C#: Dictionary<string,> preference = new Dictionary<string,>; With the "preference" object, you can specify a unique string for the key and use it to store and retrieve as many items as necessary to restore the program state. This code model is not as messy but you will always have to do some "manual labor"! Cheers, Richard
I've used up all my sick days, so today I'm calling in dead.
Hi Richard, Thanks for your reply, I am not still clear, whether do I need to manually write all the forms information? if not could you please provide a code snippet how to avoid the manual updation. Thanks
SomaShekhar
-
Hi Richard, Thanks for your reply, I am not still clear, whether do I need to manually write all the forms information? if not could you please provide a code snippet how to avoid the manual updation. Thanks
SomaShekhar
If there is any automatic save option, I don't know of it. Even if there was one provided by MS, it would generically store too much data and make the file size too large. For example, you don't want to be storing every attribute of the listView object: Font, BackColor, ForeColor, Items etc. Here's a generic example to illustrate the preference class: //Save the form's background color preferences.Add("windowsBColor", this.BackColor); -------- //Restore the windows backcolor if (preferences.ContainsKey("windowBColor")) { this.BackColor = (Color)(preferences["windowBColor"]); } If you need further assistance, don't hesitate to ask. Cheers! Richard
My code this week has no errors. But it's Monday morning and I haven't got out of bed.