当前位置:网站首页>Redraw the button and make your own circular LED indicator
Redraw the button and make your own circular LED indicator
2022-07-24 02:03:00 【yxt99】
Recently, in order to make a touch screen software for the upper computer , Customer requirements are the same as industrial touch screen interface , The indicator light is required to be made into a round . take C# Redraw the button shape in , Added gradient function from outside to inside , The code is as follows :
Practical application , add to LED After control , Modify properties type Value , The color of the indicator light will switch automatically .
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>
/// Indicator color switching
/// </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;
// Force redraw
this.Invalidate();
}
}
}
public Led()
{
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Ovalshape_Paint);
}
private void Ovalshape_Paint(object sender, PaintEventArgs e)
{
// Redraw time Draw a circle with a radial color in the center
GraphicsPath path = new GraphicsPath();
path.AddEllipse(0, 0, this.Size.Width, this.Size.Height);
PathGradientBrush pthGrBrush = new PathGradientBrush(path);
// The color of the center
pthGrBrush.CenterColor = Color.White;
// The color of the edges
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)
{
// Make the control boundary also circular
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();
}
}
}边栏推荐
- Computer room construction data
- Chapter 9.2 program control of MATLAB
- [C language operation of linked list (initialization, establishment, length calculation, addition, deletion, and output of linked list)]
- 5年接觸近百比特老板,身為獵頭的我,發現昇職的秘密不過4個字
- MD5 encryption and decryption website test, is MD5 encryption still safe?
- Number of combinations....
- Is it safe for Huatai Securities to open an account? Is it true? Is it formal
- Phpcms realizes product multi condition screening function
- Code reading methods and best practices
- Jmeter+influxdb+grafana pressure measurement real-time monitoring platform construction
猜你喜欢

Deliver temperature with science and technology, vivo protects the beauty of biodiversity

原生组件、小程序与客户端通信原理、video、map、canvas、picker等运行原理

架构实战营模块二作业

Upload files to flash file system through Arduino IDE

The difference between.Split (",", -1) and.Split (",")

Install go environment under Kali

MySQL Basics (operators, sorting and paging, multi table queries, functions)

Try to run this command from the system terminal Make sure that you use the correct

Database paradigm and schema decomposition

Draw a two coordinate diagram with MATLAB (the simplest in the whole network)
随机推荐
Code reading methods and best practices
How CAD draws arrows with arcs
NLP introduction + practice: Chapter 1: deep learning and neural network
Using tessellation in unity
毕业设计校园信息发布平台网站源码
jmeter+influxdb+grafana压测实时监控平台搭建
Chapter 9.2 program control of MATLAB
LiteSpeed Web服务器中安装SSL证书
How to use the directory classification function of the new version of easycvr (v2.5.0)?
Construction and test of hfish honey pot
Location and path planning (lingo, matlab implementation)
【MySQL】字符集utf8mb4无法存储表情踩坑记录
Jenkins multitask concurrent construction
Exchange 2010通配符SSL证书安装文档
CANopen communication - PDO and SDO
C - structure
Win11 highlights of win11 system
php7 垃圾回收机制详解
浅谈领域驱动设计
暑假第三周