Results 1 to 7 of 7

Thread: [RESOLVED] Can some one explain this logic when setting a chks state reflecting on settings

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    547

    Resolved [RESOLVED] Can some one explain this logic when setting a chks state reflecting on settings

    Basically for a while now if i wanted to set a chks setting i would do this..

    vb Code:
    1. #Region "Properties"
    2.     '//Gets or sets a value that indicates if should close to tray.
    3.     Public Property ShouldCloseToTray() As Boolean
    4.         Get
    5.             Return chkCloseToTray.Checked
    6.         End Get
    7.         Set(ByVal value As Boolean)
    8.             chkCloseToTray.Checked = value
    9.         End Set
    10.     End Property
    11. #End Region
    12.  
    13.     Private Sub chkCloseToTray_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkCloseToTray.CheckedChanged
    14.         My.Settings.CloseToTray = ShouldCloseToTray
    15.     End Sub

    But thats a lot more noise then doing it this way

    vb Code:
    1. Private Sub chkCloseToTray_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkCloseToTray.CheckedChanged
    2.         My.Settings.CloseToTray = chkCloseToTray.checked
    3.     End Sub

    whats the pros cons and which way should i be doing it???

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Can some one explain this logic when setting a chks state reflecting on settings

    save it with (ApplicationSettings).
    after you've set it up (takes a few minutes) your checkbox value will be saved on exit + restored on startup automatically

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    547

    Re: Can some one explain this logic when setting a chks state reflecting on settings

    Hello paul. Are you saying i dont have to have any code and VS has the function to save automatically???

    Can you link me to where i can set this up please

    thanks again

    on a side note, what is the different between the 2 examples i gave?

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Can some one explain this logic when setting a chks state reflecting on settings

    Quote Originally Posted by kayleigh View Post
    Hello paul. Are you saying i dont have to have any code and VS has the function to save automatically????
    yes.

    1/ select your checkbox in your form designer
    2/ expand the (ApplicationSettings) property in the properties window
    3/ select the (PropertyBinding) property + click the ellipsis to the right
    4/ in the popup window, select the checked property + click the dropdown arrow to the right
    5/ click New + in the new popup window, name the property + click ok on that window + ok on the window below + it's done


    Quote Originally Posted by kayleigh View Post
    on a side note, what is the different between the 2 examples i gave?
    they both do the same thing but 1 is a more roundabout way
    Last edited by .paul.; Oct 4th, 2010 at 11:54 AM.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    547

    Re: Can some one explain this logic when setting a chks state reflecting on settings

    Cheers paul thats great, one more question though.

    All my checkboxes are on frmOptions, which is only ever loaded if i need to change a setting.

    If i needed to get that settings value right now i would just check the boolean value of my.settings.thatchkssavedsetting

    if im not using my.settings any more how can i grab that settings value?

    if i saved it as testchksetting


    MessageBox.Show(Form2.CheckBox1.) ????

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Can some one explain this logic when setting a chks state reflecting on settings

    Quote Originally Posted by kayleigh View Post
    If i needed to get that settings value right now i would just check the boolean value of my.settings.thatchkssavedsetting
    to get the value whether the form with the checkbox is open or closed:

    vb Code:
    1. msgbox(my.settings.thatchkssavedsetting.tostring)

    edit: an important note is that each (ApplicationSetting) must have a unique name. + you can access these values through my.settings

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    547

    Re: Can some one explain this logic when setting a chks state reflecting on settings

    Thanks for the help. thats great, i can now remove a ton of coded lol

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