Tried most properties and did not manage to completely disable the focus of a checkbox in visual studio. Does anyone know how to do it?
I am using a System.Windows.Forms.CheckBox object. I am using an image as background and when the CheckBox is in focused state a border is drawn, which makes the background image look pretty bad. So I want to get rid of it...
EDIT: Adding a picture to clarify the intention of this question...
The user can tap "TAB" and click on the object to see it displayed as focused. That was a problem for me since it made the GUI look simply terrible.
The code for the CheckBox control that takes care of the painting is very elaborate, shared with Button and RadioButtion, supporting many styles. It cannot be overridden, the involved classes and methods are all internal.
But luckily you only want to mess with the focus rectangle. All you have to do is convince the control that it should not show it. That's very easy, add a new class to your project and paste the code shown below. Compile. Drop the new control from the top of the toolbox.
using System.Windows.Forms;
class MyCheckBox : CheckBox {
protected override bool ShowFocusCues {
get { return false; }
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With