当前位置:网站首页>重绘按钮,做个自己的圆形LED指示灯
重绘按钮,做个自己的圆形LED指示灯
2022-07-23 01:59:00 【yxt99】
最近为了做个上位机触摸屏软件,客户要求和工业触摸屏界面一样,要求指示灯做成圆形的。将C#中的按钮外形重绘,加入了从外到内的渐变功能,代码如下:
实际应用中,添加LED控件后,修改属性type的值,指示灯的颜色就会自动切换。
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Test
{
class Led : Button
{
private Color ledColor = Color.Silver;
private bool type_;
/// <summary>
/// 指示灯颜色切换
/// </summary>
public bool type
{
get
{
return type_;
}
set
{
if(this.type_ != value)
{
this.type_ = value;
if(!this.type_)
ledColor = Color.Silver;
else
ledColor = Color.Lime;
//强制重绘
this.Invalidate();
}
}
}
public Led()
{
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Ovalshape_Paint);
}
private void Ovalshape_Paint(object sender, PaintEventArgs e)
{
//重绘时 画出中心放射颜色的圆形
GraphicsPath path = new GraphicsPath();
path.AddEllipse(0, 0, this.Size.Width, this.Size.Height);
PathGradientBrush pthGrBrush = new PathGradientBrush(path);
//中心的颜色
pthGrBrush.CenterColor = Color.White;
//边缘的颜色
Color[] colors = new Color[] { this.ledColor };
pthGrBrush.SurroundColors = colors;
e.Graphics.FillEllipse(pthGrBrush, 0, 0, this.Size.Width, this.Size.Height);
path.Dispose();
pthGrBrush.Dispose();
}
protected override void OnPaint(PaintEventArgs pevent)
{
//使控件边界也为圆形
GraphicsPath gp = new GraphicsPath();
gp.AddEllipse(0, 0, this.Width, this.Height);
this.Region = new System.Drawing.Region(gp);
base.OnPaint(pevent);
base.OnPaint(pevent);
gp.Dispose();
}
}
}边栏推荐
- 【HLS】流水线仿真之排队函数的调用
- Canal 03 (8 chapters in total)
- 肽核酸PNA-多肽suc-Ala-Ala-Pro-Aaa-pNa|Suc-Ala3-pNA|Pyr-Phe-Leu-pNA
- PNA PNA modified polypeptide bz- (DL) - Arg PNA | z-ala-ala-leu-pna | suc ala ala ala PNA
- 1059 Prime Factors
- PNA肽核酸修饰多肽Z-Gly-Pro-pNA|D-Phe-Pip-Arg-pNA|Tos-Gly-Pro-Arg-pNA
- Ardunio——ULN2003驱动板和直流电机风扇——控制风扇转速
- Weekly recommended short video: why write such a book?
- LEADTOOLS 20-22 Crack-DotNetCore!!!
- QML(17)——读写txt文件
猜你喜欢

opensmile简介和安装过程中遇到的问题记录

PNA modified polypeptide BZ Val Gly Arg PNA | BOC Val Leu Gly Arg PNA

判断两个类型是否相同

Déterminer s'il s'agit d'un type vide

使用递归字符串反转和全排列

1、 Buildreoot directory structure

手把手教你在群晖中设置阿里云DDNS

PNA modified polypeptide suc ala Pro ala PNA | suc ala Glu Pro Phe PNA

EasyV半年度“官方网站热门内容”排行榜盘点

How to determine the end point of a software test
随机推荐
TDengine 助力西门子轻量级数字化解决方案 SIMICAS 简化数据处理流程
1059 Prime Factors
Teach you how to set up Alibaba cloud DDNS in Qunhui
Keyword Driven
【HLS】流水线仿真之排队函数的调用
毕业1年,放弃实习机会,在家自学软件测试,同学实习刚结束,我已成月薪12k测试工程师
污水处理厂设备巡检的解决方案
Solution of equipment inspection in sewage treatment plant
Salary increase artifact
MongoDB的CRUD操作(2)
Ardunio——ULN2003驱动板和直流电机风扇——控制风扇转速
Leetcode 110. 平衡二叉树
PNA modified polypeptide suc ala Pro ala PNA | suc ala Glu Pro Phe PNA
Tidb 3.0安装
结合实战,浅析GB/T 28181(二)——设备目录同步
一、buildroot目录结构
VirtualBox NAT network mode configuration
PNA肽核酸修饰多肽Z-Gly-Pro-pNA|D-Phe-Pip-Arg-pNA|Tos-Gly-Pro-Arg-pNA
【洛谷】P1318 积水面积
Accumulation of FPGA errors