Reputation: 665
i want to have a group of check boxes like CheckListBox with different back colores . is there any way for me to have this group and edit at run time?
i use the code bellow but it is cant be in different back colors:
foreach (var color in _colors)
{
var tmpCheckBox = new CheckBox
{
// Location = objLocation,
BackColor = color,
Text = color.Name
};
objLocation.X = objOffset;
objLocation.Y += tmpCheckBox.Height + objOffset;
clbColorAnalyzeResult.Items.Add(tmpCheckBox);
}
just to mention this: clbColorAnalyzeResult.Controls.Add(tmpCheckBox); will not help because there is no scroll bar and i cant use the selected index!
thanx in advance.
Upvotes: 0
Views: 185
Reputation: 16565
You have to add the checkbox to the Controls
property of your form.
Maybe you will have to create you own custom list box and override the OnDrawItem method. Something like this:
class MyCheckedListBox : CheckedListBox
{
protected override void OnDrawItem(DrawItemEventArgs e)
{
}
}
Upvotes: 1
Reputation: 79
Do this!
You should add the checkboxes to a Panel
, and set AutoScroll
to true, to get the scrollbars. You can subscribe to the GotFocus
and LostFocus
event to determine which checkbox is selected.
Upvotes: 1