Saving Controls' setting/status

kobezt08

Member
Joined
Dec 30, 2004
Messages
6
Programming Experience
Beginner
What is the best way of saving the setting of the controls in a form to a file? or How to do it?
Example: State of checkbox. state/value of TrackBar .etc
 
Well i saved the class and used it in my project but its not working i mean its method Initialize do not raise exception but the SetOption raise exception like this :

System.NullReferenceException: Object reference not set to an instance of an object.
at SIS.ConfigOpt.SetOption(String OptionName, String OptionValue) in D:\Projects\SIS\ConfigOpt.vb:line 81
at SIS.frmSettings.btnApply_Click(Object sender, EventArgs e) in D:\Projects\SIS\frmSettings.vb:line 943

Now i thought it may be due to some mis management in my project so i create a new project and just add this class and the form1 code is as follows :

PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Try
ConfigOpt.SetOption("CheckBox1.Checked", CheckBox1.Checked.ToString)
ConfigOpt.SetOption("CheckBox2.Checked", CheckBox2.Checked.ToString)
ConfigOpt.SetOption("CheckBox3.Checked", CheckBox3.Checked.ToString)
ConfigOpt.SetOption("CheckBox4.Checked", CheckBox4.Checked.ToString)
ConfigOpt.Store()
Catch ex As Exception
MsgBox(ex.ToString)
EndTry
EndSub
PrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
ConfigOpt.Initialize(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile)
EndSub
PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
EndSub

Here are just 4 checkboxes whose checked properties are stored in the configuration file and still the error is same

System.NullReferenceException: Object reference not set to an instance of an object.
at WindowsApplication1.ConfigOpt.SetOption(String OptionName, String OptionValue) in C:\Documents and Settings\rajputt\My Documents\Visual Studio Projects\WindowsApplication1\ConfigOpt.vb:line 82
at WindowsApplication1.Form1.Button1_Click(Object sender, EventArgs e) in C:\Documents and Settings\rajputt\My Documents\Visual Studio Projects\WindowsApplication1\Form1.vb:line 120

So can anyone tell where the problem is?
I need it urgently for the settings of my application. Please help me out
Thanks
Raheel
 
Back
Top