Reputation: 940
I have a form that has ten checkBoxes. They all have the exact same code in them and by that I mean a single call to a method. I'm just curious is there a way to have a single generic CheckedChanged event?
private void checkBox_one_CheckedChanged(object sender, EventArgs e)
{
enableImage();
}
private void checkBox_two_CheckedChanged(object sender, EventArgs e)
{
enableImage();
}
I've got ten of those. Is there anyway to simplify this so I can just have a single event that captures them all?
Upvotes: 0
Views: 1595
Reputation: 2142
Hold Shift, select the check boxes in question, press F4 and assign the event to all check boxes at once.
Upvotes: 1
Reputation: 2546
You only need to attach the same event to all of checkboxes:
<CheckBox Name="_chkOne" Checked="CheckBox_Checked" IsChecked="{Binding
Path=IsSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged }"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
<CheckBox Name="_chkTwo" Checked="CheckBox_Checked" IsChecked="{Binding
Path=IsSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged }"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
Upvotes: 5