danielkelly
IS-IT--Management
Hi All,
I have created my first custom user control which is basically a CheckBox displayed as a button with a few labels on it. Now Im struggling a bit with understanding the concepts of how events should be working.
When I go into my User Control and click on the CheckBox, I created an event which fires on Checked_Changed which depresses the button and changes the color. This works perfectly when I use a standard Windows Checkbox as Ive used it in other projects but not when using my custom control. I drag a few of my controls onto the form and put Visual Studio in Debug mode to start at the CheckedChanged event to see what happens.
The problem appears to be that sometimes I have to click 4 or 5 times to make the event fire and sometimes it doesnt even fire.
Am I correct in assuming that I only need the event created in the custom control and not each instance of the control on the form, as eventually I will have about 50 of these controls on the form. When i look at the custom control on the main form it does not have a CheckedChanged event.
Thanks in advance,
Daniel.
Code Sample :-
private void chkButton_CheckedChanged(object sender, EventArgs e)
{
if (chkButton.Checked == true)
{
chkButton.BackColor = Color.Lime;
lblPager.BackColor = Color.Lime;
lblTimer.BackColor = Color.Lime;
}
else
{
chkButton.BackColor = SystemColors.Control;
lblPager.BackColor = SystemColors.Control;
lblTimer.BackColor = SystemColors.Control;
}
}
I have created my first custom user control which is basically a CheckBox displayed as a button with a few labels on it. Now Im struggling a bit with understanding the concepts of how events should be working.
When I go into my User Control and click on the CheckBox, I created an event which fires on Checked_Changed which depresses the button and changes the color. This works perfectly when I use a standard Windows Checkbox as Ive used it in other projects but not when using my custom control. I drag a few of my controls onto the form and put Visual Studio in Debug mode to start at the CheckedChanged event to see what happens.
The problem appears to be that sometimes I have to click 4 or 5 times to make the event fire and sometimes it doesnt even fire.
Am I correct in assuming that I only need the event created in the custom control and not each instance of the control on the form, as eventually I will have about 50 of these controls on the form. When i look at the custom control on the main form it does not have a CheckedChanged event.
Thanks in advance,
Daniel.
Code Sample :-
private void chkButton_CheckedChanged(object sender, EventArgs e)
{
if (chkButton.Checked == true)
{
chkButton.BackColor = Color.Lime;
lblPager.BackColor = Color.Lime;
lblTimer.BackColor = Color.Lime;
}
else
{
chkButton.BackColor = SystemColors.Control;
lblPager.BackColor = SystemColors.Control;
lblTimer.BackColor = SystemColors.Control;
}
}