c# 自定义按钮,渐变颜色(含中心向四周渐变,单方向渐变)
废话不多言,直接代码:
public class RoundButton : Button
{
bool clickBool = false;
//1.设置圆形
//2.设置渐变色
//3.设置tooltip
//4.设置点击之后渐变色,tooltip
ToolTip toolTip = new ToolTip();
public RoundButton()
{
toolTip.AutoPopDelay = 1000;
toolTip.SetToolTip(this, "A: B分列选图。");
}
[Browsable(true), DefaultValue(90), Description("按钮主体颜色渐变方向,X轴顺时针开始")]
[Category("Appearance")]
public int GradientAngle { get; set; }
protected override void OnPaint(PaintEventArgs pevent)
{
base.OnPaintBackground(pevent);
RectangleF rect = new RectangleF(0, 0, this.Width, this.Height); //两种brush使用 LinearGradientBrush和PathGradientBrush
//Graphics g = pevent.Graphics;
//g.SmoothingMode = SmoothingMode.AntiAlias;//抗锯齿
//Color FColor = Color.Orange;
//Color TColor = Color.White;
//Brush b = new LinearGradientBrush(rect, FColor, TColor, 45, false);
//g.FillEllipse(b, pevent.ClipRectangle);
if (!clickBool)
{
Graphics g = pevent.Graphics;
g.SmoothingMode = SmoothingMode.AntiAlias;//抗锯齿
GraphicsPath graphicsPath = new GraphicsPath();
graphicsPath.AddEllipse(rect);
PathGradientBrush pathGradientBrush = new PathGradientBrush(graphicsPath);
pathGradientBrush.CenterColor = Color.White;
pathGradientBrush.CenterPoint = new PointF(this.Width / 2, this.Height / 2);
pathGradientBrush.SurroundColors = new Color[] { Color.Orange };
g.FillPath(pathGradientBrush, graphicsPath);
}
else
{
Graphics g = pevent.Graphics;
g.SmoothingMode = SmoothingMode.AntiAlias;//抗锯齿
GraphicsPath graphicsPath = new GraphicsPath();
graphicsPath.AddEllipse(rect);
PathGradientBrush pathGradientBrush = new PathGradientBrush(graphicsPath);
pathGradientBrush.CenterColor = Color.White;
pathGradientBrush.CenterPoint = new PointF(this.Width / 2, this.Height / 2);
pathGradientBrush.SurroundColors = new Color[] { Color.Blue };
g.FillPath(pathGradientBrush, graphicsPath);
}
} protected override void OnMouseClick(MouseEventArgs e)
{
base.OnMouseClick(e);
clickBool = !clickBool;
if (clickBool)
{
toolTip.SetToolTip(this, "4 幅图任选。");
}
else
{
toolTip.SetToolTip(this, "A: B分列选图。");
}
}
}
c# 自定义按钮,渐变颜色(含中心向四周渐变,单方向渐变)的更多相关文章
- Android 学习笔记二 自定义按钮形状 颜色 点击渐变
问题:自定义按钮的颜色 形状弧度 渐变效果 1.新建自定义属性button_login.xml (借鉴某大神) <?xml version="1.0" encoding=& ...
- CAGradientLayer渐变颜色动画
CAGradientLayer渐变颜色动画 或许你用过CAGradientLayer,你知道他是用于渐变颜色的,但你是否直到,CAGradientLayer的渐变颜色是可以动画的哦. 源码: // / ...
- 自定义iOS7导航栏背景,标题和返回按钮文字颜色
在iOS7下,默认导航栏背景,颜色是这样的,接下来我们就进行自定义,如果你仅仅是更改一下背景和颜色,代码会很简单,不需要很复杂的自定义View来替代leftBarItem 更改导航栏的背景和文字Col ...
- 【转】自定义iOS7导航栏背景,标题和返回按钮文字颜色 -- 不错不错!!
原文网址:http://blog.csdn.net/mad1989/article/details/41516743 在iOS7下,默认导航栏背景,颜色是这样的,接下来我们就进行自定义,如果你仅仅是更 ...
- 【转】 自定义iOS7导航栏背景,标题和返回按钮文字颜色
原文:http://blog.csdn.net/mad1989/article/details/41516743 UIBarButtonItem,navigationItem,backBarButto ...
- 在VS2005中设置WPF中自定义按钮的事件
原文:在VS2005中设置WPF中自定义按钮的事件 上篇讲了如何在Blend中绘制圆角矩形(http://blog.csdn.net/johnsuna/archive/2007/08/13/17407 ...
- Flutter 中的常见的按钮组件 以及自定义按钮组件
Flutter 里有很多的 Button 组件很多,常见的按钮组件有:RaisedButton.FlatButton. IconButton.OutlineButton.ButtonBar.Float ...
- 22Flutter中的常见的按钮组件 以及自定义按钮组件
/* Flutter中的常见的按钮组件 以及自定义按钮组件 一.Flutter中的按钮组件介绍 Flutter里有很多的Button组件,常见的按钮组件有:RaisedButton/FlatButto ...
- Dynamics CRM2011中通过JS脚本方式显示和隐藏ribbon中的自定义按钮
首先该方法不能写在页面的onload中,因为当从子网格返回常规表单的时候ribbon区域会重新加载而常规表单所在的iframe区域是不会被刷新的,所以如果写在onload中的话就控制的不那么完全了,我 ...
随机推荐
- .net Core 学习笔记(实体字段映射,IOC注入)
https://github.com/wj1034184751/ADO.NetCore.git 先简单的做一个学习架子, EF层用的是 EFCore(2.1.0)+ Pomelo.EntityFram ...
- WPF 精修篇 多属性触发器
原文:WPF 精修篇 多属性触发器 多属性触发器就是多个属性都满足在触发 在属性触发器上加了一些逻辑判断 举栗子 这个栗子里 textBox 要满足俩个条件 才能触发背景变色 1)textbox的 ...
- Python - 解释器 - 第三天
Python解释器 安装好Python3.x之后,我们可以使用文本文件去编写Python代码,编写完成后将扩展名改成.py结尾的文本文件. 想要执行编写好的.py文件就需要用到Python解释器. 解 ...
- 2019 医渡云java面试笔试题 (含面试题解析)
本人5年开发经验.18年年底开始跑路找工作,在互联网寒冬下成功拿到阿里巴巴.今日头条.医渡云等公司offer,岗位是Java后端开发,因为发展原因最终选择去了医渡云,入职一年时间了,也成为了面试官 ...
- iis url 重写
1.选择网站-找到有测url 重写 :2:选中它,在右上角有一个打开功能,点击打开 3.依然在右上角,点击添加规则 4:选择第一个,空白规则 名称随便输入,我们通常有这样一个需求,就是.aspx 后缀 ...
- 实验吧——你真的会PHP吗?(intval范围 php中\00的利用)
题目地址:http://ctf5.shiyanbar.com/web/PHP/index.php 抓包在header中发现提示 访问得到源码 <?php $info = "" ...
- Android源码分析(十)-----关机菜单中如何添加飞行模式选项
一:关机菜单添加飞行模式选项 源码路径:frameworks/base/core/res/res/values/config.xml 增加<item>airplane</item&g ...
- Easypoi实现单模板生成多页wrod文档
EasyPoi可以很方便的通过一个word模板,然后通过填充模板的方式生成我们想要的word文档.但是碰到了一个单模板生成多页数据的场景,比如一个订单详情信息模板,但是有很多订单,需要导入到一 ...
- AMQP与RabbitMQ
转载请注明原文地址:https://www.cnblogs.com/ygj0930/p/10922433.html 一:AMQP是什么 AMQP(Advanced Message Queuing Pr ...
- 使用Deployment控制器创建Pods并使Service发布到外网可访问
由于NFS支持节点共同读取及写入,所以可使用Deployment控制器创建多个Pod,并且每一个Pod都共享同一个目录 k8s-master kubnet@hadoop2 volumes]$ vim ...