C#复选框样式图像

时间:2015-03-19 18:19:37

标签: c# image winforms checkbox

是否有可能创建一个像复选框一样的图像?或者通过将其替换为2个图像来设置复选框的样式,一个用于未选中,另一个用于选中?我没有找到类似的东西。谢谢:))

1 个答案:

答案 0 :(得分:0)

public class CheckBoxImage : PictureBox
{
    private bool cchecked;
    private Image ci;
    public Image CheckedImage
    {
         get
         {
             return ci;
         }
         set
         {
             ci = value;
         }
    }
    private Image uci;
    public Image UnCheckedImage
    {
        get
        {
            return uci;
        }
        set
        {
           uci = value;
        }
    }
    public bool Checked
    {
        get
        {
            return cchecked;
        }
        set
        {
            if (value)
            {
                Image = CheckedImage;
            }
            else
            {
                Image = UnCheckedImage;
            }
            cchecked = value;
        }
    }
    public CheckBoxImage(Image checkedimage, Image uncheckedimage)
    {
        CheckedImage = checkedimage;
        UnCheckedImage = uncheckedimage;
        Click += (sender, e) => { Checked = !Checked; };
    }
}

我认为应该这样做。只需将其放在表单上,​​就像使用普通PictureBox一样。