! Help ! How to save user setting on program exit

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
7 posts Page 1 of 1
Contributors
User avatar
Mr.Wilson
New Member
New Member
Posts: 24
Joined: Sat Apr 23, 2011 3:42 pm

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
User avatar
Cheatmasterbw
Coding God
Coding God
Posts: 1506
Joined: Fri Jan 01, 2010 2:30 pm

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()
http://www.megaapps.tk/
User avatar
Mr.Wilson
New Member
New Member
Posts: 24
Joined: Sat Apr 23, 2011 3:42 pm

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
Public 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
User avatar
Bogoh67
VIP - Site Partner
VIP - Site Partner
Posts: 656
Joined: Sun Apr 18, 2010 8:20 pm

Code: Select all
Private 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
Last edited by Bogoh67 on Mon Nov 14, 2011 2:33 pm, edited 1 time in total.
User avatar
M1z23R
VIP - Donator
VIP - Donator
Posts: 622
Joined: Tue Sep 28, 2010 4:55 pm

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
User avatar
Mr.Wilson
New Member
New Member
Posts: 24
Joined: Sat Apr 23, 2011 3:42 pm

! 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 all
Public 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.
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

Code: Select all
Public 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
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;


Over 30 projects with source code!
Please give reputation to helpful members!

Image
Image
7 posts Page 1 of 1
Return to “Coding Help & Support”