Results 1 to 13 of 13

Thread: [2005] Saving Settings and Loading Settings Help

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2006
    Posts
    63

    [2005] Saving Settings and Loading Settings Help

    Hey, if anyone could help, would appreciate it.
    I will try and explain as well as i can.

    The problem is that i need to be able to save the font settings, fore color settings and background image/color settings.
    User loads image on (Form Appearance)
    he loads background color
    He clicks button "save all"
    (Code for that button)
    Code:
    My.Settings.BackColor = PicBoxBackColour.BackColor 'saving the settings'
            My.Settings.Font = TxtFont.Font
            My.Settings.ForeColor = TxtFont.ForeColor
            ScreenLock.BackColor = Me.PicBoxBackColour.BackColor
            ScreenLock.ForeColor = Me.TxtFont.ForeColor
            ScreenLock.Font = Me.TxtFont.Font
            ScreenLock.BackgroundImage = Me.BackgroundImage
    When i exit the form and reload it i want the settings to automatically load to the form "Screenlock"

    Here is the code for the screenlock load.
    Code:
    Me.BackColor = My.Settings.BackColor        'Loading the settings'
            Me.ForeColor = My.Settings.ForeColor
            Me.Font = My.Settings.Font
            ForeColor = My.Settings.ForeColor
            Font = My.Settings.Font
            'Do Backgroundimage'
            TxtPassbox.Font = Font
            Me.Height = Screen.PrimaryScreen.Bounds.Height      'Setting screen size'
            Me.Width = Screen.PrimaryScreen.Bounds.Width
    If you do not understand please ask and i will try to rephrase it.

    Thanks

  2. #2
    Lively Member Shardox's Avatar
    Join Date
    Nov 2006
    Location
    Barcelona, Spain
    Posts
    123

    Re: [2005] Saving Settings and Loading Settings Help

    Select your form and in its properties go to [Application Settings]>[PropertyBinding]. There you can select the different properties (Font, Forecolor, Backcolor...) and link them with the elements in my.settings object. Doing so, you don't need to add code for screenlock load or button save all. New settings will be saved automatically when you close the application (if you have not changed the default settings at the application tab in MyProject) or whenever you want by calling My.Settings.Save

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2006
    Posts
    63

    Re: [2005] Saving Settings and Loading Settings Help

    I am not very experienced with Visual Basic.net yet, so would you be able to explain in a bit more detail and step by step a bit more please.
    I can find the property Bindings, But don't understand the linking with the elements in my.settings object. And how no code is required.

    If its asking to much, its fine.
    Thanks

  4. #4
    Lively Member Shardox's Avatar
    Join Date
    Nov 2006
    Location
    Barcelona, Spain
    Posts
    123

    Re: [2005] Saving Settings and Loading Settings Help

    Directly from msdn:

    http://msdn2.microsoft.com/en-us/lib...9h(VS.80).aspx

    To bind a property to an existing application setting using Visual Studio

    1.

    Select the form or control which defines the property to which you want to bind your setting.
    2.

    On the Property Editor, expand the (ApplicationSettings) node near the top of the grid; this will reveal the (PropertyBindings) node.
    3.

    Click the empty cell next to the (PropertyBindings) node, and then click the ellipsis button (...) that appears.
    4.

    On the Application Settings dialog box, find the property you want to bind and select the drop-down list next to it. The list shows all of the settings in your application. If you have organized your settings into groups, or have added multiple settings classes in your project, you will see your settings arranged as a hierarchical tree, with the setting group name in bold and the settings belonging to that group underneath it.
    5.

    Select the setting to which you want to bind this property by activating the check box next to the setting's name.
    6.

    Close the Application Settings dialog box.

    .............



    Once you have bound your settings to the corresponding properties of your form (or any other object), any change you make to the setting will affect the property with no need of extra code.

    For example, if the backcolor property of one form is bound to my.settings.myformcolor then by setting my.settings.myformcolor=color.blue
    the backcolor of the form will change automatically, and that value will be saved when you exit the application or whenever you do my.settings.save

  5. #5
    Lively Member smilbuta's Avatar
    Join Date
    Apr 2005
    Location
    Orlando
    Posts
    104

    Re: [2005] Saving Settings and Loading Settings Help

    I never knew about app settings before.

    Can this also be used to store specific selections within an app sucha as a default selection?? (ill explain)

    User has list box,
    List box contains 3 items
    index item 0 is the app default
    User selects index item 1
    User closes app
    user repoens the app and now Index item 1 is the selcted default

    IS this possible with settings? or woudl one have to implement some other method of storing a value of the indexed item to be called upon load??
    VB.Net uber-noob since04, Yeababy!

  6. #6
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] Saving Settings and Loading Settings Help

    Yes it is possible.

    If you go to Settings and add a variable called: cboChoice for example.

    Then go back to your form, add a combobox, fill it with some items. Then Bind it as described by Shardox. Then on form Closing or something you can do this:

    vb Code:
    1. My.Settings.cboChoice = Me.ComboBox1.SelectedItem.ToString
    2. My.Settings.Save()
    3. Application.Exit()

    When you reload the form the last item should be there. At least I think that's how it works.
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  7. #7
    Lively Member Shardox's Avatar
    Join Date
    Nov 2006
    Location
    Barcelona, Spain
    Posts
    123

    Re: [2005] Saving Settings and Loading Settings Help

    Also notice that this is the easiest way to make your application fully customizable, just adding a propertygrid control and setting the my.settings object as the selectedobject for the propertygrid.

    - Double Click on MyProject
    - Select the 'Settings' tab
    - Add all the settings you need by indicating:
    - Name for the property
    - Type (String, Color, Integer,ConnectionString...)
    - Scope (The scope of the property: user/application)
    - Value (The default value for this setting)
    - Now you can add this properties to any control in your form:
    - Click any control to select it
    - In the propertygrid of the control go to:
    (ApplicationSettings)>(PropertyBinding)
    - Now select any property and bind it to one of the settings you created before.
    - The last thing you have to do is adding a PropertyGrid to a form in your application and set:
    VB Code:

    PropertyGrid1.SelectedObject = My.Settings


    Thats all. The user can change the values of the settings on the propertygrid and all the controls within the application bound to these settings will show the changes.

  8. #8
    Lively Member smilbuta's Avatar
    Join Date
    Apr 2005
    Location
    Orlando
    Posts
    104

    Re: [2005] Saving Settings and Loading Settings Help

    oh..oh!.. niceeee....
    Thanx! to you both!
    VB.Net uber-noob since04, Yeababy!

  9. #9
    Lively Member
    Join Date
    Jun 2007
    Posts
    115

    Re: [2005] Saving Settings and Loading Settings Help

    does this work in 2002?

    i dont see where the appication settings node is... and there is a property pages icon on the top of the property box that is greyed. I see a databindings window.. but the drop down choice are all "none" with no other option...

    Last edited by jeffnyc; Jul 13th, 2007 at 11:00 AM.

  10. #10
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2005] Saving Settings and Loading Settings Help

    Quote Originally Posted by jeffnyc
    does this work in 2002?
    No... it doesn't work on 2002/2003 because the My namespace is new in 2005 and you won't find it in previous versions.

  11. #11
    Hyperactive Member NPassero's Avatar
    Join Date
    May 2007
    Location
    NJ
    Posts
    272

    Re: [2005] Saving Settings and Loading Settings Help

    That helps a lot for my application. Got themes, start up fonts and everything.

  12. #12
    Lively Member
    Join Date
    Jun 2007
    Posts
    115

    Re: [2005] Saving Settings and Loading Settings Help

    Say I bind the font to a property variable called myFont, if I change the user changes the font of that control during runtime do I have to also set my.settings.myFont to the result of the font dialog in addition to to the control's font property?
    Last edited by jeffnyc; Jul 14th, 2007 at 05:08 PM.

  13. #13
    Lively Member
    Join Date
    Jun 2007
    Posts
    115

    Re: [2005] Saving Settings and Loading Settings Help

    Ok, I misunderstood, basically all the settings are accessible through the project's property window not just the property bindings if form objects.

    I have a checked listbox of about 400 items. Currently I read and write the items and the checked state to/from a text file. Would it make sense to just use appsettings and bind the checked listbox collection to my settings instead of doing my own file io? Or is that taking this feature too far
    Last edited by jeffnyc; Jul 15th, 2007 at 01:01 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width