Reputation: 376
Actually on a WinForms project (VS 2010, C#, .NET 4.5), I build a matrix (10x10) in a form. Each element is represented by a control that can be "checked" or "unchecked". Each element's state is completely independent of another.
The ideal solution would be to use a CheckBox. Unfortunately, the client wants a different appearance - for example, the one of the RadioButton. I could use RadioButton, place every one of them in a dedicated group, add an event listener to uncheck on-click if the element is already checked... Pretty much for a question of appearance!
Couldn't I override some rendering methods of CheckBox class? (Anyway, that's the only place in the whole application where I use this control)
Note: Controls are instanciated on runtime from a class MyClass:CheckBox.
Upvotes: 4
Views: 1869
Reputation: 941218
Use a RadioButton if you need to make it look like one. You'll need to set their AutoCheck property to False to make them act like check boxes and give them a common event handler:
private void radioButtons_Click(object sender, EventArgs e) {
var button = (RadioButton)sender;
button.Checked = !button.Checked;
}
Never hesitate to point out that this is very poor UI design.
Upvotes: 6