Create OwnerDraw CheckBox

  • Thread starter Thread starter Thomas Kehl
  • Start date Start date
T

Thomas Kehl

Hi.

Does anybody have a sample, how does I can make a checkBox ownerdrawn? I
need to change the color inside of the box.

Can anyone help me, how does I have to do this?

Thanks
Thomas
 
I'm not I understand what exactly you want to do..but, you can change both
the foreground and background color of the standard
System.Windows.Forms.CheckBox usinng the ForeColor & BackColor Properties.

Thanks,
Mohamed
--------------------
 
Hi Mohamed,

thanks for your answer. I want to change the color inside of the box where
the hook is in it (this is always white), not of the textarea.

Can you help me?

Thanks, Thomas
 
Thomas,

I going to assume you ment a WinForm CheckBox.
With that said here is how I would do it.

Add an ImageList Control to the Form. To hold the 16x16 images used as
the check box area of the control.
Image 1: Image of an Unchecked box
Image 2: Image of a box with a check in it
Image 3: Image of a Indeterminate Box with a check in it (Only if 3
state)

Add a Paint Event to the check box the the following code.
private void CheckBox1_Paint(object sender, PaintEventArgs e)
{
if( CheckBox1.Checked )
e.Graphics.DrawImageUnscaled( ImageList1.Images[1],
0, // X start point
0 ); // Y start point
else
e.Graphics.DrawImageUnscaled( ImageList1.Images[0],
0, // X start point
0 ); // Y start point
}

Note: Forms will be slowed during load the more check boxes you have
to draw.

Hopes this helps.

Glen Jones MCSD
 
Back
Top