SaveSetting and GetSetting in C#

How to use SaveSetting() and GetSetting() methods of VB in C#?

Lets see,

SaveSetting() method is used to store UI input data and GetSetting() method is used to retrieve that stored data.

//Save textbox1's value
SaveSetting (App.EXEName, "textboxes", "textbox1", textbox1.Text)

//Get textbox1's value
textbox1.text = GetSetting (App.EXEName, "textboxes", "textbox1", "")


SaveSetting stores the data in the Registry (in HKEY_CURRENT_USER|Software|VB and VBA Program Settings|YourAppName). The four parts of the function are the name under which it is stored (App.EXEName in this case), "textboxes" in this example is like the section name in an ini file, "textbox1" is like the key in a line of data in the ini file, and textbox1.text is the value.

GetSetting returns the value. The 4th parameter ("" in this case) is optional and it is the default if no registry entry is found.

If you use these functions in C# then you have to add reference of "Microsoft.VisualBasic" to your project.

and after that you can use SaveSettings and GetSettings functions as below,

using Microsoft.VisuaBasic;

Interaction.SaveSetting (App.EXEName, "textboxes", "textbox1", textbox1.Text);

textbox1.text=Interaction.GetSetting (App.EXEName, "textboxes", "textbox1", "");

Comments

Post a Comment

Popular posts from this blog