Take the 2-minute tour ×

Working on a WinForms .Net 2.0 project, I need a checkbox to support multiple lines such that the box itself will be aligned to the top-left corner.
This is done using CheckAlign = System.Drawing.ContentAlignment.TopLeft, which different from the default (MiddleLeft).

When working with the default font this looks OK, but when the font becomes larger - what happens is that the gap above the text increases, yet the gap above the box itself remains constant.
The result is that the box appears above the text (see illustration below).

Any ideas?

I'd like to note that:

  1. I already tried a few option, such as using a custom designer, a TableLayoutPanel, etc., but didn't get far.
  2. .Net 2.0 is forced - upgrading is not an option.

Thanks in advance.

CheckBox Issues

share|improve this question
I don't think you have a lot of options here. Maybe a checkbox without text next to a label with text. –  LarsTech Apr 18 '12 at 17:02
Thanks, but as mentioned I already tried that (in a TableLayoutPanel). The end result is the same - the gap above the box remains static while above the text it increases as the font size increases... –  AVIDeveloper Apr 18 '12 at 20:34

1 Answer 1

up vote 1 down vote accepted

The checkbox is actually aligned to the text. But in a way that could only please a typographer. It is just that a large font has more ascender height, the space where the diacritics go. Try "Ĥere's the problem". That's not something you can tinker. CheckedListBox also doesn't support owner draw, it is in general a pretty flawed control. If you don't want to use an ownerdraw ListBox then MiddleLeft or smaller fonts are the only decent options.

enter image description here

share|improve this answer
Thanks for the eye-opener! Just a slight correction - I'm not looking for the CheckedListBox, I'm looking for a CheckBox replacement. Is there a way to calculate the ascender's height? (without it - I don't see how an owner-drawn solution could help) –  AVIDeveloper Apr 18 '12 at 20:42
I have an idea: Upon a FontChanged event, I blit a 'W' into a bitmap, then scan it top->bottom counting empty (white) pixels. The first non-empty pixel should be the height of the ascender. –  AVIDeveloper Apr 18 '12 at 21:04
Ah, I was wondering how you got the screenshot. But yes, exact same problem with CheckBox. The hackorama with pixel scanning is okayish as long as you do it for the entire line of text. I'd personally would just make it clear where the checkbox starts and ends so that the centered checkbox looks entirely natural. Easy to do with the Paint event. –  Hans Passant Apr 18 '12 at 21:09
[Yep, it's a top->down FlowLayoutPanel.] Centered box is not the problem. My challenge is to perfectly align the box with the first line of text. All in all I think we're on the same page here, so thanks for your much appreciated help - your questions-answering is art. –  AVIDeveloper Apr 18 '12 at 21:29
Thanks for the compliment, appreciated. –  Hans Passant Apr 18 '12 at 21:56

Your Answer


