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并发编程实战》阅读指南 - 第8章
先发表生成URL以印在书里面.等书籍正式出版销售后会公开内容.
- WPF 精修篇 事件触发器
原文:WPF 精修篇 事件触发器 事件触发器 一般使用的就是动画 <Grid> <TextBlock Text="事件触发器" Opacity="0.2 ...
- ABP——切换MySQL数据库
我是一名.net新手,应公司要求开始学习.net,使用的是土耳其大牛写的框架ASP.NET Boilerplate 简称ABP,是基于DDD的现代ASP.NET开发框架,ABP提供了一个启动模板用于新 ...
- html提示信息框淡入淡出效果(自己的思路,如果有更好的思路,请留言)
使用方法: 调用initMessagebox(“要显示的文字”)方法即可 <!--信息框--> <div id="messagebox"></div& ...
- C# 身份证号码15位和18位验证
/// <summary> /// 身份证 /// </summary> [Serializable] public class IDCard { /// <su ...
- .NET Core的依赖注入
转自[大内老A] 依赖注入[1]: 控制反转依赖注入[2]: 基于IoC的设计模式依赖注入[3]: 依赖注入模式依赖注入[4]: 创建一个简易版的DI框架[上篇]依赖注入[5]: 创建一个简易版的DI ...
- PostgreSQL查询当前时间的时间戳
一.问题 使用PostgreSQL获取当前系统时间戳.众所周知,在MySQL中是这样的: select UNIX_TIMESTAMP(NOW()) 二.解决方案 (1)精确到秒 " (2)精 ...
- 2-Rocketmq产品架构(参考阿里云)
参考链接:https://help.aliyun.com/document_detail/112008.htm
- vue+element创建动态的form表单.以及动态生成表格的行和列
动态创建form表单,网上有插件 (form-create) 不过我不知道它怎么用,没有使用成功,如果你使用成功了,欢迎下方留言. 最后我使用了笨方法,针对各个表单写好通用的组件,然后根据type用v ...
- webrtc (6) 在Webrtc中集成VideoToolbox
来源:http://blog.csdn.net/wangruihit/article/details/46550853 VideoToolbox是iOS平台在iOS8之后开放的一个Framework, ...