using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;

namespace ColorCheckControls
{
    public class CustomCheckBox: CheckBox
    {
        private Color _CheckColor;

        private void PaintHandler(object sender, PaintEventArgs args)
        {
            if (this.Checked)
            {
                Point pt = new Point();

                if (this.CheckAlign == ContentAlignment.BottomCenter)
                {
                    pt.X = () - ;
                    pt.Y = ;
                }

                if (this.CheckAlign == ContentAlignment.BottomLeft)
                {
                    pt.X = ;
                    pt.Y = ;
                }

                if (this.CheckAlign == ContentAlignment.BottomRight)
                {
                    pt.X = ;
                    pt.Y = ;
                }

                if (this.CheckAlign == ContentAlignment.MiddleCenter)
                {
                    pt.X = () - ;
                    pt.Y = () - ;
                }

                if (this.CheckAlign == ContentAlignment.MiddleLeft)
                {
                    pt.X = ;
                    pt.Y = () - ;
                }

                if (this.CheckAlign == ContentAlignment.MiddleRight)
                {
                    pt.X = ;
                    pt.Y = () - ;
                }

                if (this.CheckAlign == ContentAlignment.TopCenter)
                {
                    pt.X = () - ;
                    pt.Y = ;
                }

                if (this.CheckAlign == ContentAlignment.TopLeft)
                {
                    pt.X = ;
                    pt.Y = ;
                }

                if (this.CheckAlign == ContentAlignment.TopRight)
                {
                    pt.X = ;
                    pt.Y = ;
                }

                DrawCheck(args.Graphics, this.CheckColor, pt);
            }
        }

        private void DrawCheck(Graphics g, Color c, Point pt)
        {
            Pen pen = new Pen(c);
            g.DrawLine(pen, pt.X, pt.Y + , pt.X + , pt.Y + );
            g.DrawLine(pen, pt.X, pt.Y + , pt.X + , pt.Y + );
            g.DrawLine(pen, pt.X, pt.Y + , pt.X + , pt.Y + );
            g.DrawLine(pen, pt.X + , pt.Y + , pt.X + , pt.Y - );
            g.DrawLine(pen, pt.X + , pt.Y + , pt.X + , pt.Y);
            g.DrawLine(pen, pt.X + , pt.Y + , pt.X + , pt.Y + );
        }

        public CustomCheckBox()
        {
            this._CheckColor = ForeColor;
            this.Paint += new PaintEventHandler(this.PaintHandler);
        }

        [Description("CheckBox复选框颜色")]
        public Color CheckColor
        {
            get
            {
                return _CheckColor;
            }
            set
            {
                _CheckColor = value;
                Invalidate();
            }
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;

namespace ColorCheckControls
{
    public class CustomColorRadioButton: RadioButton
    {
        private Color _CheckColor;

        private void PaintHandler(object sender, PaintEventArgs args)
        {
            if (this.Checked)
            {
                Point pt = new Point();
                if (CheckAlign == ContentAlignment.BottomCenter)
                {
                    pt.X = () - ;
                    pt.Y = ;
                }

                if (CheckAlign == ContentAlignment.BottomLeft)
                {
                    pt.X = ;
                    pt.Y = ;
                }

                if (CheckAlign == ContentAlignment.BottomRight)
                {
                    pt.X = ;
                    pt.Y = ;
                }

                if (CheckAlign == ContentAlignment.MiddleCenter)
                {
                    pt.X = () - ;
                    pt.Y = () - ;
                }

                if (CheckAlign == ContentAlignment.MiddleLeft)
                {
                    pt.X = ;
                    pt.Y = () - ;
                }

                if (CheckAlign == ContentAlignment.MiddleRight)
                {
                    pt.X = ;
                    pt.Y = () - ;
                }

                if (CheckAlign == ContentAlignment.TopCenter)
                {
                    pt.X = () - ;
                    pt.Y = ;
                }
                if (CheckAlign == ContentAlignment.TopLeft)
                {
                    pt.X = ;
                    pt.Y = ;
                }
                if (CheckAlign == ContentAlignment.TopRight)
                {
                    pt.X = ;
                    pt.Y = ;
                }

                DrawCheck(args.Graphics, this.CheckColor, pt);
            }
        }

        private void DrawCheck(Graphics g, Color c, Point pt)
        {
            /*
            Pen pen = new Pen(c);
            g.DrawLine(pen, pt.X, pt.Y + 1, pt.X + 4, pt.Y + 1);
            g.DrawLine(pen, pt.X-1, pt.Y + 2, pt.X + 5, pt.Y + 2);
            g.DrawLine(pen, pt.X, pt.Y + 3, pt.X + 4, pt.Y + 3);
            g.DrawLine(pen, pt.X + 1, pt.Y, pt.X + 1, pt.Y + 4);
            g.DrawLine(pen, pt.X + 2, pt.Y-1, pt.X + 2, pt.Y + 5);
            g.DrawLine(pen, pt.X + 3, pt.Y, pt.X + 3, pt.Y + 4);
             * */
            Brush brush = new SolidBrush(c);
            g.FillEllipse(brush, pt.X-, pt.Y-, , );
        }

        public CustomColorRadioButton()
        {
            this._CheckColor = this.ForeColor;
            this.Paint += new PaintEventHandler(this.PaintHandler);
        }
        [Description("按钮颜色")]
        public Color CheckColor
        {
            get
            {
                return _CheckColor;
            }
            set
            {
                _CheckColor = value;
                Invalidate();
            }
        }
    }
}

点我下载

自定义颜色显示的CheckBox的更多相关文章

  1. 【Android学习】自定义Android样式checkbox

    下面简单介绍下在Androdi中如何更改Checkbox的背景图片,可以自定义样式 1.首先res/drawable中定义编写如下样式的XML,命名为:checkbox_style: <?xml ...

  2. 自定义input[type="checkbox"]的样式

    对复选框自定义样式,我们以前一直用的脚本来实现,不过现在可以使用新的伪类 :checkbox 来实现. 如果直接对复选框设置样式,那么这个伪类并不实用,因为没有多少样式能够对复选框起作用.不过,倒是可 ...

  3. 原生javascript自定义input[type=checkbox]效果

    2018年6月27日  更新 能用css3,就不用js 用纯css3实现样式重写 <!DOCTYPE html> <html lang="en"> < ...

  4. 自定义radio、checkbox的样式

    input标签中的radio和checkbox是很表单中常用的类型,大多时候,默认样式并不能满足我们的需求,所以有了此篇. 自定义样式,由此开启: html: <div class=" ...

  5. 关于input 的选中,自定义input[type="checkbox"]样式

    1.css 呈现   选中后 的input的样式可以用 /*背景图*/      background:url('../pc/images/archives/icon_choosed.png') no ...

  6. ZH奶酪:纯CSS自定义Html中Checkbox复选框样式

    原文链接:http://www.lrxin.com/archives-683.html 首先看下效果: 点击演示地址查看实例. 首先,需要添加一段CSS隐藏所有的Checkbox复选框,之后我们会改变 ...

  7. 自定义input[type="checkbox"]样式

    input[type=checkbox] { visibility: hidden; position: relative;} input[type=checkbox]:after { content ...

  8. WPF CheckBox 自定义样式

    WPF 自定义样式.CheckBox <Style x:Key="EmptyCheckBox" TargetType="CheckBox"> < ...

  9. 自定义checkbox样式

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

随机推荐

  1. 跨域请求之jQuery的ajax jsonp的使用解惑

    前天在项目中写的一个ajax jsonp的使用,出现了问题:可以成功获得请求结果,但没有执行success方法,直接执行了error方法提示错误——ajax jsonp之前并没有用过,对其的理解为跟普 ...

  2. python 接口开发(一)

    cmd中,提示pip版本太低,先升级pip   pip install --upgrade pip (pip,安装和管理python扩展包的工具) cmd下,pip,出现详细信息证明装成功了 pip ...

  3. C#语法问答式总结

    传入某个属性的set方法的隐含参数的名称是什么?value,它的类型和属性所声名的类型相同. 如何在C#中实现继承?在类名后加上一个冒号,再加上基类的名称. C#支持多重继承么?不支持.可以用接口来实 ...

  4. java互斥方法

    synchronized,  lock/unlock,  volatile类型变量, atom类, 同步集合,  新类库中的构件: CountDownLatch\CyclicBarric\Semaph ...

  5. python数据分析入门——matplotlib的中文显示问题&最小二乘法

    正在学习<用python做科学计算>,在练习最小二乘法时遇到matplotlib无法显示中文的问题.查资料,感觉动态的加上几条语句是最好,这里贴上全部的代码. # -*- coding: ...

  6. 【LeetCode】Rotate Array

    Rotate Array Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = ...

  7. IAP 程序内购

    最近用到IAP内置购买,阅读官方文档,在网上找了些资料,在这里作下整理,以便日后查找和修改,主要流程方向确定,文档和相关转载内容截图不一一指出,google一堆. 1.查找官方文档,两张目录截图,对主 ...

  8. Piggy-Bank_完全背包

    Description Before ACM can do anything, a budget must be prepared and the necessary financial suppor ...

  9. 后台代码对iBatis配置文件中具体的sql语句的调用实现(被封装的增删改查)

    using IBatisNet.Common.Exceptions; using IBatisNet.DataAccess; using IBatisNet.DataAccess.DaoSession ...

  10. Unity3D ShaderLab 模拟精灵动画

    Unity3D ShaderLab 模拟精灵动画 在上一篇,介绍了通过Shader 模拟纹理运动,那么更深一步讲,我们也可以把帧动画的精灵纹理运动通过shader实现. 虽然大家都是在游戏脚本中做更高 ...