Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WinForm
Hello all,
 
here's a pretty simple question I guess:
 
I added user settings to a couple of checkboxes for my WinForm following this MSDN article: http://msdn.microsoft.com/en-us/library/aa730869%28v=vs.80%29.aspx[^]
 
I use VS 2012 Express for Desktop.
 
There's an easy way to add a setting for a control by choosing "new" in the application settings properties of the control. This is what I did, and it works as expected: All checkboxes remain their last state when the form loads.
 
BUT: the checkboxes toggle the visibility of some labels when the CheckedChanged event occurs:
 
private void cbExample_CheckedChanged(object sender, EventArgs e)
        {
            lblLabel.Visible = cbExample.Checked;            
        }
 
When the form first loads, the checkboxes are checked, but the labels remain invisible until I manually uncheck and check the cb again.
 
What's the proper way to make sure all checked checkboxes, radio buttons and so on do what they should right away?
 
Thanks for your support,
Best
Dennis
Posted 2-Jan-13 0:04am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

When the form loads, the event cbExample_CheckedChanged is not called (it only gets executed when checkbox is clicked), so the label remains invisible.
 
You need to do this in form load event.
  Permalink  
v2
Comments
Tadit Dash at 2-Jan-13 5:41am
   
No you don't need to call cbExample_CheckedChanged manually, that is the inbuilt event for checkbox.
You just need to write the codes which you want to execute inside the form load.
 
Write something like below inside the form load event, but don't call the event....

if(cbExample.Checked)
{
lblLabel.Visible = cbExample.Checked;
}
Tadit Dash at 2-Jan-13 6:03am
   
For this, please check CheckBox.DoubleClick Event and try to implement the codes inside this event.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi,
 
The check change event attach after set of initial values, which you can set from property window.
 
So the event is not firing.
 
If you know what is you initial values are then you can easily set which label's you want to visible.
 
Or
 
You can set you default value after
InitializeComponent()
function. Then event will fire.
 
Smile | :)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Alright, thanks; so do I have to call every single cb*_CheckedChanged manually in the form load event?
  Permalink  

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 565
1 Maciej Los 359
2 Kornfeld Eliyahu Peter 309
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,303
1 DamithSL 4,764
2 Maciej Los 4,306
3 Kornfeld Eliyahu Peter 3,914
4 Sergey Alexandrovich Kryukov 3,538


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 2 Jan 2013
Copyright © CodeProject, 1999-2014
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