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. android 回调函数

    http://blog.csdn.net/xiaanming/article/details/8703708 此为回调的java 实例 http://www.cnblogs.com/qingchen1 ...

  2. [流媒体]live555简介(转)

    live555简介 Live555 是一个为流媒体提供解决方案的跨平台的C++开源项目,它实现了对标准流媒体传输协议如RTP/RTCP.RTSP.SIP等的支持.Live555实现 了对多种音视频编码 ...

  3. 一点点webservice的小知识

    怕自己忘了记录下来好了 在web.config中要配置自己要调用的webservice的地址 在自己controller中获取web.config中配置的地址 SystemManager.Config ...

  4. hdoj-2019

    #include "stdio.h"void sort(int number[],int n,int m);int main(){ int n,m,i,number[100]; s ...

  5. 猜猜两道Java基础面试题的结果

    class TA { public String s = "A"; public String getS() { return s; } } class TB extends TA ...

  6. 极客DIY:使用树莓派制作一架四轴无人机

    如果你想DIY一台属于自己的无人机,那么接下来可以阅读这篇文章,阅读完毕之后也许对你会有启发. 这个项目主要用到的零件主要来自Erle Robotics(一个使用Linux系统的开源四轴飞行器项目). ...

  7. Cookies和Session的区别

    原文:http://www.cnblogs.com/lijihong/p/4743818.html 今天主要学习了Cookies和Session,网络上关于这方面的知识可谓很多,让人眼花缭乱,在此作一 ...

  8. BZOJ 2083 Intelligence test

    用vector,二分. #include<iostream> #include<cstdio> #include<cstring> #include<algo ...

  9. linux常用命令:1文件处理命令

    文件处理命令 1.命令格式 命令格式:命令 [-选项]  [参数] 例:ls  -la /etc 说明:1)个别命令使用不遵循此格式 2)档有多个选项时,可以写在一起 3)简化选项与完整选项 2.目录 ...

  10. Application,Session,Cookie,ViewState和Cache区别

    在ASP.NET中,有很多种保存信息的内置对象,如:Application,Session,Cookie,ViewState和Cache等.下面分别介绍它们的用法和区别. 方法 信息量大小 作用域和保 ...