Settings Help
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.
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
If i have CheckBox1 to 4 on a form, how would i make it so when i close the form and then open the program again the check state of all the checkboxes are the same as when they were when the form closed.
I would like to know how to make this without making a file (that includes temp files)
thanks!
I would like to know how to make this without making a file (that includes temp files)
thanks!
Add 4 settings.
CHK1 - Boolean - True
CHK2 - Boolean - False
CHK3 - Boolean - False
CHK4 - Boolean - False
Under Form_FormClosing, put:
If Checkbox1.checked = true then
my.settings.chk1 = true
elseif checkbox2.checked = true then
my.settings.chk2 = true
elseif...
etc
and under Form Load
If my.settings.chk1 = true then
checkbox1.checked = true
etc.
+rep if I helped!
CHK1 - Boolean - True
CHK2 - Boolean - False
CHK3 - Boolean - False
CHK4 - Boolean - False
Under Form_FormClosing, put:
If Checkbox1.checked = true then
my.settings.chk1 = true
elseif checkbox2.checked = true then
my.settings.chk2 = true
elseif...
etc
and under Form Load
If my.settings.chk1 = true then
checkbox1.checked = true
etc.
+rep if I helped!

he said making temp files this doesnt save for ever.
Nailing my feet to the floor is easier than using my own muscles to balance, but you don't see me doing that 

I actually did not want temp files. Thanks Reboh, +1 Rep for you!
EDIT: When making a setting, What would the scope be in this situation? "User", "Application", or does it not matter? Thanks!
EDIT: When making a setting, What would the scope be in this situation? "User", "Application", or does it not matter? Thanks!
Really helpful, Reboh. I'll be using this in my next application, which will be a Text To Speech application.
I figured it out! Application is read only, and User is not!
Last time I tested settings, it kept them when I moved the program to a different directory and stuff. The settings stayed the same at all times. Thanks Cheatmaster and Usman!
I want to do it with textbox, how to save its text so that next time the form loads, its text is same.
Hello Usman55,
it's simple, you'll just have to create a settings and put it to string(And string is the default) And no value.
Have a button saying "Save" (There is no need for a button, you can save it on formclosing but I prefer with both)
it's simple, you'll just have to create a settings and put it to string(And string is the default) And no value.
Have a button saying "Save" (There is no need for a button, you can save it on formclosing but I prefer with both)
Code: Select all
Private Sub txtSettingsName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSettingsName.TextChanged
If txtSettingsName.Text = "" Then
btnSave.Enabled = False
Else
btnSave.Enabled = True
End If
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
My.Settings.test = txtSettingsName.Text
My.Settings.Save()
My.Settings.Reload()
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
My.Settings.test = txtSettingsName.Text
My.Settings.Save()
My.Settings.Reload()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
txtSettingsName.Text = My.Settings.test
End Sub
Thanks Agust, I wanted this piece of code badly, thanks. And can you help me with a simple thing? I want my application if the directory which is written in a textbox exists then it's okay but if it doesn't exists than it should create one. It should be a text file though. I tried some code but it made a folder named Log.txt instead of a file.
Copyright Information
Copyright © Codenstuff.com 2020 - 2023