Changing backcolor of a checkbox

  • Thread starter Thread starter Elif
  • Start date Start date
E

Elif

How can I change the back color of a checkbox, not its label, but the actual
checkbox?

Thanks,
Elif
 
* "Elif said:
How can I change the back color of a checkbox, not its label, but the actual
checkbox?

You will have to draw the control yourself (for example, by deriving a
class from 'CheckBox' and overriding its 'OnPaint' method.
 
OnPaint method has a System.Windows.Forms.PaintEventArgs parameter. This is
a general paint method for the whole control including its label, checkbox
and background. The ClipRectangle property shows the boundaries of the
whole control, if this is the first time the control is being painted, or
just the area of the checkbox if it is being repainted. So in the OnPaint
method do I need to do the following?:

1. First call MyBase.OnPaint, so that the checkbox is drawn as it normally
would.

1. Figure out the exact location of the checkbox based on the
ClipRectangle property.

2. Paint that location to the color I want.

3. Draw the check mark on that location if the checkbox is checked.

Am I going in the right direction? It feels like there must be an easier
way of doing this.

Thanks for any help.

Elif
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top