自定义颜色显示的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> ...
随机推荐
- [转] Linux内核代码风格 CodingStyle [CH]
from:http://blog.csdn.net/jiang_dlut/article/details/8163731 中文版维护者: 张乐 Zhang Le <r0bertz@gentoo. ...
- a Makefile
obj-m += showpid.o obj-m += ps.o all: make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) mo ...
- object_c函数多个返回值
- (void)readStr1:(NSString**)str1 andStr2:(NSString**)str2{ NSString *s1 = @"1"; NSS ...
- operation not possible due to RF-kill
使用mdk3时出现这个问题operation not possible due to RF-kill 就是输入第一条命令 后出现 operation not possible due to RF-ki ...
- nginx添加未编译安装模块
链接:http://taokey.blog.51cto.com/4633273/1318719
- Linux在IA-32体系结构下的地址映射
1.概览 2.逻辑地址到线性地址 逻辑地址到线性地址的映射在IA-32体系结构中又被称为段式映射.如上图所示,段式映射我们首先需要获取逻辑地址和段选择符,段选择符用于获取GDT中段的基地址,将逻辑地址 ...
- STL 源码分析《2》----nth_element() 使用与源码分析
Select 问题: 在一个无序的数组中 找到第 n 大的元素. 思路 1: 排序,O(NlgN) 思路 2: 利用快排的 RandomizedPartition(), 平均复杂度是 O(N) 思路 ...
- typedef的用法
我最开始学习的是C++,而不是C语言.虽说C++涵盖了C,但是C++的语法更加方便,比如输入输出……但是为了与C兼容,常常需要保留C语言的用法,这就比较烦人了,因为我们都希望有一个固定的语法. 首先让 ...
- java IO流的体系结构图
常用字节流字符流 字节流 InputStream ...
- C#_WinForm接收命令行参数
C#_WinForm接收命令行参数 2014-08-03 10:17 534人阅读 评论(0) 收藏 举报 首先,我要仔细的声明下,本文讲的是接受命令行参数,让程序启动.而不是启动那个黑黑的框...我 ...