Click here to Skip to main content
11,493,391 members (61,385 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
Hi,
It's the first time I deal with settings.
I have a simple application which could be displayed in its standard (small) size, when mnuStandard is checked or in its advanced (large) size, when mnuAdvanced is checked.
How to save the setting the user had chosen.

I went to proprieties----->settings

string1:mnuStandard boolean false
string2:mnuAdvanced boolean false

This the code for the two menu items.(until now I'm unable to code for settings)
And thank you in advance for your help.


Private Sub mnuStandard_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuStandard.Click
        If sender Is Me.mnuStandard Then
            Me.mnuStandard.Checked = True
            Me.Width = 500
            Me.Height = 500
            Me.mnuAdvanced.Checked = False
        End If
 
 Private Sub mnuAdvanced_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAdvanced.Click
        If sender Is Me.mnuAdvanced Then
            Me.mnuAdvanced.Checked = True
            Me.Width = 600
            Me.Height = 600
            Me.mnuStandard.Checked = False
end if
Posted 25-Feb-13 11:05am
Comments
CHill60 at 25-Feb-13 16:25pm
   
Have a look here http://www.dondraper.com/2011/01/easily-save-and-retrieve-application-and-user-settings-in-vb-net-or-c-apps/

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Here is a simple way to do it using the Windows Registry:

1. In the program's Form Load Event retrieve the settings
        Dim strMenuType As String = CSTR(Microsoft.VisualBasic.Interaction.GetSetting("MyAppName", "Menu", "Type", "Standard")) ' Default to Standard
        If strMenuType = "Standard" Then
            Me.mnuStandard.Checked = True
            Me.Width = 500
            Me.Height = 500
            Me.mnuAdvanced.Checked = False
        Else
            Me.mnuAdvanced.Checked = True
            Me.Width = 600
            Me.Height = 600
            Me.mnuStandard.Checked = False
        End If

2. Save the settings when the user selects the option in the program's menu
    Private Sub mnuStandard_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuStandard.Click
            Me.mnuStandard.Checked = True
            Me.Width = 500
            Me.Height = 500
            Me.mnuAdvanced.Checked = False
            Microsoft.VisualBasic.Interaction.SaveSetting("MyAppName", "Menu", "Type", "Standard")
    End Sub
    Private Sub mnuAdvanced_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAdvanced.Click
            Me.mnuAdvanced.Checked = True
            Me.Width = 600
            Me.Height = 600
            Me.mnuStandard.Checked = False
            Microsoft.VisualBasic.Interaction.SaveSetting("MyAppName", "Menu", "Type", "Advanced")
   
   End Sub
  Permalink  
v6
Comments
Member 9863518 at 25-Feb-13 17:12pm
   
Hi,
Really I thank you very much for your help.
In 1 All the first line is jagged until its last word showing there's a problem.

I replaced "myAppName", but what should I do with "Menu" ,"Type" ? excuse my question
ThePhantomUpvoter at 25-Feb-13 17:45pm
   
http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.interaction.getsetting.aspx
Mike Meinz at 25-Feb-13 18:34pm
   
I added CSTR() to GetSettings statement in Solution 1 above.

"Menu" and "Type" are values that you choose. I used those specific values because they described the data that you wanted to save. You can use them or choose other values. After saving your settings, you can look in the Registry (RegEdit.exe) to see the value(s) stored at this key name: HKEY_CURRENT_USER\Software\VB and VBA Program Settings

See the Microsoft Visual Studio Help file:
GetSetting
SaveSetting
Mike Meinz at 26-Feb-13 16:01pm
   
Did my Solution 1 help you? If so, please accept Solution 1 so that the question is marked as answered.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 419
1 Maciej Los 286
2 F-ES Sitecore 224
3 KarstenK 210
4 CPallini 208
0 Sergey Alexandrovich Kryukov 10,132
1 OriginalGriff 8,630
2 Sascha Lefèvre 3,624
3 Maciej Los 3,392
4 Richard Deeming 2,500


Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 25 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100