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. 使用siege进行Web压力测试

    因为最近公司线上node项目出一些不稳定的情况,考虑在这方面能不能做进一步的优化,既然要做优化首先要知道问题出在哪里? 因为暂无法定位是node层问题还是api层出现问题,由于在开发环境小并发量程序运 ...

  2. 苹果 iOS 8 新固件新功能特性总结汇总 (苹果 iPhone/iPad 最新移动操作系统)

    苹果在 WWDC 2014 大会上正式发布了其最新的 OS X Yosemite 桌面系统以及 iOS 8 移动操作系统,虽然 iOS 8 依然延续了 iOS7 的扁平化设计风格,但在功能上却还是给我 ...

  3. 记录一些容易忘记的属性 -- UIImageView

    UIImage *image =  [UIImage imageNamed:@"back2.jpg"]; //创建一个图片对象,这个方法如果图片名称相同,不管我们调用多少次,得到的 ...

  4. IOS UTF8中文字母数字 组合时长度截取

    //计算总共字数和限制字数的Index位置 -(NSMutableArray *) unicodeLengthOfString: (NSString *) text { NSMutableArray ...

  5. TCP同步传送数据示例(简洁、清楚)

    转自:http://www.2cto.com/kf/201206/134841.html 本例子写了个简单的TCP数据传送功能.没有使用BinaryWriter,BinaryReader,而是使用Ne ...

  6. IOS9适配 MARK

    最近做了iOS 9的适配,程序出现大量警告也做了些处理,写出来分先给大家. 一.iOS 9适配 问题一: <Error>: CGContextSaveGState: invalid con ...

  7. php大力力 [008节]局部表量

    2015-08-23 php大力力008. php局部表量 开始写简单程序,遇到几个小困难障碍. 第一个:不要少写最后一个问号❓ <?php echo 'HELLO WORLD';?> 程 ...

  8. 大型HashMap

    看到一篇评估大型HashMap的文章,备份几个Collections库. 原文:Large HashMap overview: JDK, FastUtil, Goldman Sachs, HPPC, ...

  9. HDOJ-三部曲一(搜索、数学)-1008-Prime Path

    Prime Path Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) Total S ...

  10. 怎么书写高质量jQuery代码

    众所周知,jQuery现在已经非常流行,百度新首页中也已经开始使用jQuery,今天总结下怎么书写更好的jQuery代码使jQuery代码更好.更快的执行,希望本篇jQuery教程一改大家以前不合理的 ...