Click here to Skip to main content
15,888,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys,

I have created a custom checkbox using the on paint event. This is working nicely as it should however, My custom image checkbox is displayed over the existing checkbox. Is there a way for me to hide just the box of the checkbox but keep my "Checkbox" image?

Here is my code:

C#
public void CheckBox_Checked(object sender, PaintEventArgs e)
        {
            CheckBox chck = sender as CheckBox;
            if (chck.Checked)
                e.Graphics.DrawImageUnscaled((Properties.Resources.CheckboxChecked), 0, 0);
            else if (chck.Checked == false)
                e.Graphics.DrawImageUnscaled((Properties.Resources.CheckboxUnchecked), 0, 0);
        }


and this gets called as follows:

C#
CheckBox1.Paint += new PaintEventHandler(_customControls.CheckBox_Checked);
Posted
Comments
[no name] 11-Jun-15 16:10pm    
Sure. Remove the old checkbox and only show your custom image checkbox. Or subclass the checkbox control and only use that one.

1 solution

You have to override the OnPaint-Method from the control - perhaps without calling the base-method.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900