0

I would like to self-draw the checkmark of a Checkbox, as explained here.

This requires setting the CheckBox to checkBox.Appearance = Appearance.Button and then disabling the borders. Meaning, the CheckBox is now rendered as if it was a button. When it is checked, it is rendered as a depressed button.

Unfortunately, a depressed button has its text shifted slightly to the right and downwards. This behaviour is not commonly seen in a CheckBox.

Our CheckBox with Appearance set to "Button"

var cb = new Checkbox();
cb.Paint += delegate (object sender, PaintEventArgs e)
{
    // Here you can custom-draw the Checkmark.
    // (but I'd like to fix the text-shifting first)
};
cb.Appearance = Appearance.Button;
cb.TextAlign = ContentAlignment.MiddleRight;
cb.FlatStyle = FlatStyle.Flat;
cb.FlatAppearance.BorderSize = 0;

Is it possible to configure a Button (or a CheckBox configured as Button) so that the text is not shifted when it is being depressed?

LTR
  • 1,226
  • 2
  • 17
  • 39
  • 2
    No, it is [hard-coded](https://referencesource.microsoft.com/#System.Windows.Forms/winforms/Managed/System/WinForms/ButtonInternal/ButtonFlatAdapter.cs,294) against the button state. – Hans Passant Jan 08 '22 at 09:58
  • 1
    You can always derive your own Custom Control from Button or CheckBox and draw whatever you need, text or graphic, as *shifted* or not *shifted* as you please. – Jimi Jan 08 '22 at 12:22
  • 1
    You don't need to set it to the button style, just paint the control yourself, for example look at the customization [here](https://stackoverflow.com/a/38432140/3110834). – Reza Aghaei Jan 08 '22 at 17:20

0 Answers0