I am trying to change the back color of a checkbox.
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


"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:OEnokSB8DHA.2644@TK2MSFTNGP11.phx.gbl...
> * "Elif" <efanuscu@mednet.ucla.edu> scripsit:
> > 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.
>
> --
> Herfried K. Wagner [MVP]
> <http://www.mvps.org/dotnet>

Re: Changing backcolor of a checkbox by anonymous

anonymous
Wed Feb 11 15:21:05 CST 2004

There's no easier way... That's the good way... You might consider turning double buffering on

base.SetStyle(ControlStyles.DoubleBuffer, true)
base.SetStyle(ControlStyles.UserPaint, true)
base.SetStyle(ControlStyles.AllPaintInWmPaint, true)