自定义颜色显示的CheckBox

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的更多相关文章
- 【Android学习】自定义Android样式checkbox
下面简单介绍下在Androdi中如何更改Checkbox的背景图片,可以自定义样式 1.首先res/drawable中定义编写如下样式的XML,命名为:checkbox_style: <?xml ...
- 自定义input[type="checkbox"]的样式
对复选框自定义样式,我们以前一直用的脚本来实现,不过现在可以使用新的伪类 :checkbox 来实现. 如果直接对复选框设置样式,那么这个伪类并不实用,因为没有多少样式能够对复选框起作用.不过,倒是可 ...
- 原生javascript自定义input[type=checkbox]效果
2018年6月27日 更新 能用css3,就不用js 用纯css3实现样式重写 <!DOCTYPE html> <html lang="en"> < ...
- 自定义radio、checkbox的样式
input标签中的radio和checkbox是很表单中常用的类型,大多时候,默认样式并不能满足我们的需求,所以有了此篇. 自定义样式,由此开启: html: <div class=" ...
- 关于input 的选中,自定义input[type="checkbox"]样式
1.css 呈现 选中后 的input的样式可以用 /*背景图*/ background:url('../pc/images/archives/icon_choosed.png') no ...
- ZH奶酪:纯CSS自定义Html中Checkbox复选框样式
原文链接:http://www.lrxin.com/archives-683.html 首先看下效果: 点击演示地址查看实例. 首先,需要添加一段CSS隐藏所有的Checkbox复选框,之后我们会改变 ...
- 自定义input[type="checkbox"]样式
input[type=checkbox] { visibility: hidden; position: relative;} input[type=checkbox]:after { content ...
- WPF CheckBox 自定义样式
WPF 自定义样式.CheckBox <Style x:Key="EmptyCheckBox" TargetType="CheckBox"> < ...
- 自定义checkbox样式
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
随机推荐
- C# 开发XML Web Service与Java开发WebService
一.web service基本概念 Web Service也叫XML Web Service WebService是一种可以接收从Internet或者Intranet上的其它系统中传递过来的请求,轻量 ...
- CentOS 6.4 U盘启动问题的解决
替换syslinux/目录下的vesamenu.c32文件. 下载地址: http://pan.baidu.com/s/1mg8xce8
- PHP汉字转拼音类
看到的文章,转过来留用,哈哈 汉字转拼音类(全拼与首字母) <?php class GetPingYing { private $pylist = array( 'a'=>-20319, ...
- SQL Server 2005使用作业设置定时任务(转)
1.开启SQL Server Agent服务 使用作业需要SQL Agent服务的支持,并且需要设置为自动启动,否则你的作业不会被执行. 以下步骤开启服务:开始-->>>运行--&g ...
- Bayeux
Bayeux是一种用来在客户端和服务器端传输低延迟的异步消息(主要通过http)的一种协议.它定义的消息通过命名通道进行路由并且能够进行交互传 送:server -> client, clien ...
- openstack context
之前一直不知道context模块中存储的是什么东西,这回看一下代码: 其中最主要的类是:RequestContext: class RequestContext(object): "&q ...
- Python中的闭包
简单的闭包的栗子: def counter(statr_at = 0): count = 1 def incr(): nonlocal count #注意由于count类型为immutable,所以需 ...
- 使用树莓派和kali Linux打造便携式渗透套件
在DIY前你需要: .树莓派Raspberry Pi Model B+型 或者 树莓派2代; .充电宝 X1; .USB WIFI网卡 X1; .8G SD卡 X1; .Raspberry PI触摸显 ...
- 您不能在64-位可执行文件上设置DEP属性?
我是为dllhost.exe设置DEP时遇到了同样的情况.你需要选择64位系统对应的程序.64位系统:C:\Windows\SysWOW64\dllhost.exe32位系统:C:\Windows\S ...
- Interview----判断两个链表是否相交?
题目描述: 判断两个单链表是否相交?假设链表没有环. 假如链表有环呢? 1. 假如没有环 那么如果两个链表相交的话,必然最后的节点一定是同一个节点.所以只需要各自扫描一遍链表,找到最后一个节点,比较 ...