Page 1 of 1
! Help ! How to save user setting on program exit
Posted: Mon Nov 14, 2011 2:12 am
by Mr.Wilson
How would I go about saving the users settings of check boxes upon program exit using My.Settings.Save
I have on the form
1 textbox namedtxt1
3 checkboxes named chBox1-3
I want to save the current state of all these object when the program closes with out using a "save" button
Thanks in advance
P.s. I am using Visual Studio 2008
Re: ! Help ! How to save user setting on program exit
Posted: Mon Nov 14, 2011 2:16 am
by Cheatmasterbw
You can make settings with the type string and Boolean, and when the app is closing (on the form#_closing event) change all of the settings to the values of the textbox/checkboxes. after you set the values, use my.settings.save()
Re: ! Help ! How to save user setting on program exit
Posted: Mon Nov 14, 2011 4:00 am
by Mr.Wilson
Thank you for the quick reply. But I would like a coding example for the check boxes specifically. Here is what i have so far and its not working
Code: Select allPublic Class Form1
Dim Settings As New My.MySettings
Dim chBox1 As New My.MySettings
Dim chBox2 As New My.MySettings
Dim chBox3 As New My.MySettings
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
My.Settings.chBox1 = Me.chboxItem1.CheckState
End Sub
thanks again
Re: ! Help ! How to save user setting on program exit
Posted: Mon Nov 14, 2011 5:56 am
by Bogoh67
Code: Select allPrivate Sub Form1_Formclosing(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.FormClosing
End Sub
is that what you mean? and where its says me.chboxItem1 i dont think you need me
but after that line
My.Settings.chBox1 = Me.chboxItem1.CheckState
write my.settings.save
Re: ! Help ! How to save user setting on program exit
Posted: Mon Nov 14, 2011 9:59 am
by M1z23R
Mr.Wilson wrote:Thank you for the quick reply. But I would like a coding example for the check boxes specifically. Here is what i have so far and its not working
Code: Select all My.Settings.chBox1 = Me.chboxItem1.Checked
My.Settings.Save
Re: ! Help ! How to save user setting on program exit
Posted: Mon Nov 21, 2011 2:47 pm
by Mr.Wilson
! Solved ! There might be other ways to do this but this is how I did it. before I close this topic i would like someone to check it so as not to post poor info.
Code: Select allPublic Class Form1
Dim chBox1Settings As New My.MySettings
Dim chBox2Settings As New My.MySettings
Dim chBox3Settings As New My.MySettings
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
chBox1.Checked = My.Settings.chBox1Settings
chBox2.Checked = My.Settings.chBox2Settings
chBox3.Checked = My.Settings.chBox3Settings
End Sub
Private Sub btnClose_Click(sender As System.Object, e As System.EventArgs) Handles btnClose.Click
My.Settings.chBox1Settings = chBox1.CheckState
My.Settings.chBox2Settings = chBox2.CheckState
My.Settings.chBox3Settings = chBox3.CheckState
My.Settings.Save()
Close()
End Sub
Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
End Sub
End Class
Thanks again for every ones help.
Re: ! Help ! How to save user setting on program exit
Posted: Mon Nov 21, 2011 4:27 pm
by MrAksel
Code: Select allPublic Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
chBox1.Checked = My.Settings.chBox1Settings
chBox2.Checked = My.Settings.chBox2Settings
chBox3.Checked = My.Settings.chBox3Settings
End Sub
Private Sub btnClose_Click(sender As System.Object, e As System.EventArgs) Handles btnClose.Click
My.Settings.chBox1Settings = chBox1.CheckState
My.Settings.chBox2Settings = chBox2.CheckState
My.Settings.chBox3Settings = chBox3.CheckState
My.Settings.Save()
Close()
End Sub
Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
End Sub
End Class
You dont need the
Dim chBox1Settings As New My.MySettings... Its enough with just My.Settings.chBox1Settings