Hello everyone! I'm just a beginner in vb.net. I need to make a save button. The user will work in main form. User also has Settings in the MenuStrip, when the user clicks Settings a new form will open. There user has ability to make changes that will affect the Main form. This is the code:

If CheckBox1.Checked = True Then
            bib.Panel2.Hide()
        End If

This is the change that the user will be able to do that will affect the Main form, but I'm not really sure how to make that the CheckBox1 will be saved when the user clicks it and the clicks OK button. I also want to know how to make a cancel button. If you know how, help me please.
Thanks for your help.

Recommended Answers

All 8 Replies

Hi.
to save the settings that the user has made on the form just add this code to your main page.

My.Settings.Save()

This will ensure that all changes are saved and the user can exit and reurn to the program and find the changes they had previously made.

you could use this code on the cancel button

My.settings.reset()

This will put back all the default settings on the forms.
Hope this has helped you in some way.

What do you mean by "main page"?
I inserted the "My.Settings.Save()" in the save button but it doesn't work!
What's going on?

I'll agree with the settings approach, but it will take a bit more than that.
Start by going to your project properties, select the settings tab and create a new setting, naming it hide_panel for now

Go the "Settings" form and use this code

If CheckBox1.Checked = True Then
my.settings.hide_panel = "True" 
my.settings.save()
End If

Then on your main form put this in the form load sub

if my.settings.hide_panel.tostring = "True"  then 
Panel2.Hide()
end if

What is for MenuStrip use for in your problem... is it having setting...

Check out this thread.

Thanks for your help but since I'm new in vb.net I got lost very quickly after reading your post.

So in my Solution Explorer I clicked on "My Project".
Then I went to the "Settings" tab and named the setting "hide_panel".
After that I clicked on the "View Code" button which opened this up:

Namespace My
    
    'This class allows you to handle specific events on the settings class:
    ' The SettingChanging event is raised before a setting's value is changed.
    ' The PropertyChanged event is raised after a setting's value is changed.
    ' The SettingsLoaded event is raised after the setting values are loaded.
    ' The SettingsSaving event is raised before the setting values are saved.
    Partial Friend NotInheritable Class MySettings

    End Class
End Namespace

Now I'm not sure where I need to use the first code that you gave me.

I'll agree with the settings approach, but it will take a bit more than that.
Start by going to your project properties, select the settings tab and create a new setting, naming it hide_panel for now

Go the "Settings" form and use this code

If CheckBox1.Checked = True Then
my.settings.hide_panel = "True" 
my.settings.save()
End If

Then on your main form put this in the form load sub

if my.settings.hide_panel.tostring = "True"  then 
Panel2.Hide()
end if

If you're new to vb.net, work with files.
Save and load the settings from a file since you can actually see what goes on. Hope this helps, it helped me when I started w/vb.net.

Like the comments in the view code say: 'This class allows you to handle specific events on the settings class:
You don't want that code, but the one in your forms.

If you've named the setting value you are done with the project properties. Close this tab and get back to your forms.
The first portion of code I've posted should either go to the save button or to the checkbox checkedchanged event (After checkin or unchecking your checkbox). You can go to the correct event by double clicking your checkbox or by double clicking the save button.
What it does is check the state of the checkbox and set the value of the setting hide_panel.

The second one on the form with the layout load event. What it does is check the value of the setting hide_panel and hides the panel if it finds hide_panel = "True".


codeorder is right about working with files, but you'll have to create the file, open it, edit it, save it, close it, and generally do everything around it. The settings class does everything for you, so start with this and you can move forward after you got it.


PS: The panel will be hidden/ visible after restarting the program or you will need to run the form load sub after or inside the if in the 1st part of code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.