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中的话就控制的不那么完全了,我 ...
随机推荐
- Mysql系列(十一)—— 性能分析其他常用监控
show status show status可以查询显示出当前mysql server的状态信息.该语句不需要任何权限. 对于show status可以时用like子句,模糊检索需要的状态信息.如: ...
- MySQL:实用 SQL 语句集合
写在前面的话 本文主要用于记录工作中不经常使用但是偶尔用到又非常有用的 SQL 语句,持续不断不定期更新. 数据库大小统计 1. 查看 MySQL 某个库的所有表大小,记录数,占用空间等. ,), ' ...
- codis集群搭建笔记
一.安装Linux虚拟机 二.安装go运行环境 https://www.cnblogs.com/xmzncc/p/6218694.html wget http://mirrors.flysnow.or ...
- 2019-11-29-浅谈-Windows-桌面端触摸架构演进
原文:2019-11-29-浅谈-Windows-桌面端触摸架构演进 title author date CreateTime categories 浅谈 Windows 桌面端触摸架构演进 lind ...
- Go是如何生活在内存条里的【译】
原文:A visual guide to Go Memory Allocator from scratch (Golang) 当我第一次开始试图了解 Go 的内存分配器时,觉得它真令人抓狂.所有的所有 ...
- Linux 监控之 IO
简单介绍下 Linux 中与 IO 相关的内容. 简介 可以通过如下命令查看与 IO 相关的系统信息. # tune2fs -l /dev/sda7 ← 读取superblock信息 # blockd ...
- Bootstrap导航栏示例
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- python笔试题
冒泡排序的原理:每次对相邻的两个元素进行比较,若前者大于后者,这将两者的位置交换.第一轮就可以将最大的元素置于列表的最后.几轮循环 冒泡排序的前提条件:有序的列表 import unittest# 冒 ...
- emacs第二天
setq 和setq-default的区别 cursor-type是一个buffer local 变量 在每一份buffer中都有一份值 如果变量是buffer local 里面的变量 setq-de ...
- LeetCode 1216. Valid Palindrome III
原题链接在这里:https://leetcode.com/problems/valid-palindrome-iii/ 题目: Given a string s and an integer k, f ...