Tony Bogdanov Tony Bogdanov - 3 months ago 36
Vb.net Question

VB.NET: Image as checkbox state box

Is it possible to use an image as the checkbox "checked" indicator square?

I know I can use a background image, but that goes behind the label aswell and also it is not possible (as far as I know) to align it.

How can I use an image instead of the square and leave the label and all other customization as they are?

Thanks in advance!

xfx xfx
Answer

UPDATE #1: Actually, @brahm solution's below is much better than mine!

UPDATE #2: Actually, it's not. Now I see how he did it: he's moving the checkbox out of sight by placing it way off the visible Form's area. Not a great solution...


The ideal solution would be to subclass the CheckBox control and do your own rendering by overriding the OnPaint method.

An easier, although probably messier solution, would be to place a PictureBox over the check box and control the image in the PictureBox through the CheckBox's CheckedChange event.

Another option: You could still use the CheckBox in button mode (Appearance = Button), as you suggested, but then add a label right next to it. Then, handle the Click event on the Label to toggle the Checked state of the CheckBox. Then end result should provide you exactly what you are looking for.