Saving Settings With My.Settings

Blessing

User is banned.
Reputation
0
You will need:

VB 2008/2010 (I'm using 2010)
2 Forms (A default form and a 2nd form)
1 TextBox
2 CheckBoxes
1 Button
Should look something like this:
project_preview.png


Edit Texts (NOT THE NAMES):

CheckBox1 = Save Password!
CheckBox2 = Show Password
Button1 = Login

Editing My.Settings:

Go to Project > ProjectName Properties on the upper tabs.
Now go to Settings on the left tabs.
Make 3 settings.
Make "password", "passwordsave", and "checkbox1save" WITHOUT THE QUOTES!
The value of "password" should be "madebyblessing", value of "passwordsave" should be blank, and value of "checkbox1save" should be "False" WITHOUT THE QUOTES!
Should look something like this:
settings.png


Now for codes:

In Button1, put:
[vb]If TextBox1.Text = My.Settings.password = True Then ' If the value of TextBox1 is the same value as "password" then...
Form2.Show() ' Form2 shows.
ElseIf TextBox1.Text = My.Settings.password = False Then ' If the value of TextBox1 has the different value as "password" then...
MessageBox.Show("Password is not correct!", "Password Invalid") ' A message box shows saying "Password is not correct!" and with the title "Password invalid".
End If[/vb]

In CheckBox1, put:
[vb]If CheckBox1.Checked = True Then ' If CheckBox1 is checked then...
My.Settings.passwordsave = TextBox1.Text ' The value of "passwordsave" is what you type in TextBox1.
My.Settings.checkbox1save = "True" ' The value of "checkbox1save" is True.
ElseIf CheckBox1.Checked = False Then ' If CheckBox1 is not checked then...
My.Settings.passwordsave = "" ' The value of password is nothing.
My.Settings.checkbox1save = "False" ' The value of "checkbox1save" is False.
End If[/vb]

In CheckBox2, put:
[vb]If CheckBox2.Checked = True Then ' If CheckBox2 is checked then...
TextBox1.PasswordChar = "" ' The password character is plain texts.
ElseIf CheckBox2.Checked = False Then ' If CheckBox2 is not checked then...
TextBox1.PasswordChar = "*" ' The password character is *****.
End If[/vb]

In Form1_Load, put:
[vb]TextBox1.Text = My.Settings.passwordsave ' The value of TextBox1 is the same value as "passwordsave".
CheckBox1.Checked = My.Settings.checkbox1save ' The value of checked True/False of CheckBox1 is the same value as "checkbox1save". So if the value of "checkbox1save" is False, then CheckBox1 won't be checked.[/vb]

And your done!
Please +Rep me :D
 
This I like.

This will become bery usefull. Thanks very much :D
 
Back
Top