废话不多言,直接代码:

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# 自定义按钮,渐变颜色(含中心向四周渐变,单方向渐变)的更多相关文章

  1. Android 学习笔记二 自定义按钮形状 颜色 点击渐变

    问题:自定义按钮的颜色 形状弧度  渐变效果 1.新建自定义属性button_login.xml (借鉴某大神) <?xml version="1.0" encoding=& ...

  2. CAGradientLayer渐变颜色动画

    CAGradientLayer渐变颜色动画 或许你用过CAGradientLayer,你知道他是用于渐变颜色的,但你是否直到,CAGradientLayer的渐变颜色是可以动画的哦. 源码: // / ...

  3. 自定义iOS7导航栏背景,标题和返回按钮文字颜色

    在iOS7下,默认导航栏背景,颜色是这样的,接下来我们就进行自定义,如果你仅仅是更改一下背景和颜色,代码会很简单,不需要很复杂的自定义View来替代leftBarItem 更改导航栏的背景和文字Col ...

  4. 【转】自定义iOS7导航栏背景,标题和返回按钮文字颜色 -- 不错不错!!

    原文网址:http://blog.csdn.net/mad1989/article/details/41516743 在iOS7下,默认导航栏背景,颜色是这样的,接下来我们就进行自定义,如果你仅仅是更 ...

  5. 【转】 自定义iOS7导航栏背景,标题和返回按钮文字颜色

    原文:http://blog.csdn.net/mad1989/article/details/41516743 UIBarButtonItem,navigationItem,backBarButto ...

  6. 在VS2005中设置WPF中自定义按钮的事件

    原文:在VS2005中设置WPF中自定义按钮的事件 上篇讲了如何在Blend中绘制圆角矩形(http://blog.csdn.net/johnsuna/archive/2007/08/13/17407 ...

  7. Flutter 中的常见的按钮组件 以及自定义按钮组件

    Flutter 里有很多的 Button 组件很多,常见的按钮组件有:RaisedButton.FlatButton. IconButton.OutlineButton.ButtonBar.Float ...

  8. 22Flutter中的常见的按钮组件 以及自定义按钮组件

    /* Flutter中的常见的按钮组件 以及自定义按钮组件 一.Flutter中的按钮组件介绍 Flutter里有很多的Button组件,常见的按钮组件有:RaisedButton/FlatButto ...

  9. Dynamics CRM2011中通过JS脚本方式显示和隐藏ribbon中的自定义按钮

    首先该方法不能写在页面的onload中,因为当从子网格返回常规表单的时候ribbon区域会重新加载而常规表单所在的iframe区域是不会被刷新的,所以如果写在onload中的话就控制的不那么完全了,我 ...

随机推荐

  1. Python程序调试工具Py-Spy

    序言 如果你是从Java语言开发转Python开发,可能在庆幸自己的开发效率提高了很多,但是也有痛苦的时候,比如你会怀念jstack,jmap, 等各种工具在生产环境做perfomance tunin ...

  2. net输出错误日志

    在使用net开发webapi的时候,有时候程序异常了,外面只能看到一个错误:an error occur 怎么才能将具体的 错误堆栈信息输出来呢? 1.在startup.cs文件中添加如下代码就可以将 ...

  3. windows10 edge浏览器关闭没有提示如何解决

    通常情况下,用户在win10 edge中打开多个窗口,点击关闭按钮就会出现“要关闭所有标签”提示,然后可以点击 取消来取消关闭edge.不过,最近一位windows10系统用户反馈自己在一次勾选“总是 ...

  4. Python - 基本数据类型 - 第二天

    Python3 基本数据类型 Python 中的变量不需要声明.每个变量在使用前都必须赋值,变量赋值以后该变量才会被创建. 在 Python 中,变量就是变量,它没有类型,我们所说的"类型& ...

  5. Mac系统docker初探

    最近把工作环境要切到mac中,由于一直想看看docker是怎么回事,以前在win和linux下面都没有用起来,这次在mac中决定试一把,尝试下新的环境部署方式. 安装docker mac中,直接有类似 ...

  6. 为什么你要使用这么强大的分布式消息中间件——kafka

    为什么是kafka? 在我们大量使用分布式数据库.分布式计算集群的时候,是否会遇到这样的一些问题: 我们想分析下用户行为(pageviews),以便我们设计出更好的广告位 我想对用户的搜索关键词进行统 ...

  7. java--Date时间

    Date: 表示特定的瞬间,精确到毫秒,通过方法设定自己所表示的时间,可以表示任意的时间 System.currentTimeMillis() :返回的当前系统时间, 1970-1-1 至今的毫秒数 ...

  8. 隐马尔科夫模型(Hidden Markov Models) 系列之四

    转自:http://blog.csdn.net/eaglex/article/details/6430389 前向算法(Forward Algorithm) 一.如果计算一个可观察序列的概率?   1 ...

  9. iOS 原生推送(APNS)的实现

    1.前期准备工作 创建你的APNs keys 或者 创建推送证书,这两个创建一个即可实现推送.这两个创建一个即可实现推送.这两个创建一个即可实现推送.重要的事情说三遍,我看评论区有小伙伴误解. 1.  ...

  10. ORACLE ORION测试IO性能

    https://www.oracle.com/technetwork/cn/topics/index-088165-zhs.html 下载地址 Orion是Oracle提供的IO性能测试工具,运行该工 ...