现有CheckBox控件显示的自定义CheckBox控件 [英] Custom CheckBox Control Shown Over Existing CheckBox Control

查看:111
本文介绍了现有CheckBox控件显示的自定义CheckBox控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我使用on paint事件创建了一个自定义复选框。这很好用,但是,我的自定义图像复选框显示在现有复选框上。有没有办法让我只隐藏复选框的方框,但保留我的复选框图像?



这是我的代码:



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:

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:

CheckBox1.Paint += new PaintEventHandler(_customControls.CheckBox_Checked);

推荐答案

你必须从控件中覆盖OnPaint-Method - 也许不用调用base-method。
You have to override the OnPaint-Method from the control - perhaps without calling the base-method.


这篇关于现有CheckBox控件显示的自定义CheckBox控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆