Arrow[Help] save settings.

Posts 1–13 of 13 · Page 1 of 1
[Help] save settings.
i have a group box and in it is two radiobuttons so only 1 will be selected. so if i select one of them and restart my program, How can i make it so the same radiobutton is checked??? is it involved with registry setting or does it involve creating an .ini file???



sorry i am really new at saving...
Well you can do a property I believe...

I'd rather just have a .ini file however, but that's just me.
Quote Originally Posted by hopefordope View Post
i have a group box and in it is two radiobuttons so only 1 will be selected. so if i select one of them and restart my program, How can i make it so the same radiobutton is checked??? is it involved with registry setting or does it involve creating an .ini file???



sorry i am really new at saving...
Well, you can use registry to do this. Put the following code in Form_Closed Event:

[php]For Each x As Control In GroupBox1.Controls
If x.GetType.Name = "RadioButton" Then
Dim i As RadioButton = x
If i.Checked Then
SaveSetting(Application.ProductName, "Settings", "CheckedButton", i.Name)
End If
End If
Next[/php]

Now put the following code in the Form_Load Event:

[php]Dim x As String = GetSetting(Application.ProductName, "Settings", "CheckedButton", "")
If Not x = "" Then
Dim ctrl As RadioButton = GroupBox1.Controls(x)
ctrl.Checked = True
End If[/php]

If necessary change the control names with yours !!

Tested and working. Hope this helps !!
Wow FlameSaber you really know your VB
Quote Originally Posted by Invidus View Post
Wow FlameSaber you really know your VB
Thank you. It just depends on the level of enthusiasm
looks like we have another NG at MPGH
Hmm. Not quite yet. I don't think Flamesaber has the level of experience that NextGen has attained. But he's getting there..
Quote Originally Posted by Invidus View Post
Hmm. Not quite yet. I don't think Flamesaber has the level of experience that NextGen has attained. But he's getting there..
Yup, he is much much more experienced than me. In programming experience counts a lot. NextGen1 really is a great vb programmer !!
really sorry for bumping this but how do i get the Form_Unload thing
Flamesaber's method is probs better than mine but this is how I do it.

Go to the "Project" tab and go to properties.

Go to the settings tab and create a new setting type, call it...Checker1 or something you want change it to boolean and default False, then do that again call it checker2 (for your second radio button)

Now in your project add this to RadioButton1_Checkchanged or something

Code:
My.Settings.Checker1 = RadioButton1.checked
My.Settings.Checker2 = RadioButton2.checked
My.Settings.Save()
My.Settings.Reload()
and add the same thing to RadioButton2_Checkchanged sub

Then on your Form1_Load add this

Code:
RadioButton1.checked = My.Settings.Checker1
RadioButton2.Checked = My.Setting.Checker2
That works alright I think, didn't test it.
when i do tht then i cant click anything in my app
it freezes
Quote Originally Posted by hopefordope View Post
when i do tht then i cant click anything in my app
it freezes
My Method or flamesabers?

EDIT: Tested my method and it worked. Make sure when you added the settings you set the type to "Boolean" not string and it's default value to false

In case you're having trouble with the code section, this is my whole code.

[php]Public Class Form1

Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
My.Settings.Checker1 = RadioButton1.Checked
My.Settings.Checker2 = RadioButton2.Checked
My.Settings.Save()
My.Settings.Reload()
End Sub

Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
My.Settings.Checker1 = RadioButton1.Checked
My.Settings.Checker2 = RadioButton2.Checked
My.Settings.Save()
My.Settings.Reload()
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
RadioButton1.Checked = My.Settings.Checker1
RadioButton2.Checked = My.Settings.Checker2
End Sub
End Class[/php]
By choosing Boolean as value it automaticlly sets the value on "False" by default.
Posts 1–13 of 13 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us