Winform-自定义按钮_三色灯图标

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing.Drawing2D;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Management.Instrumentation;
namespace MyContrl
{
/// <summary>
/// 指示灯
/// </summary>
public partial class RoundButton : ToolStripButton
{
protected override void OnPaint(PaintEventArgs pevent)
{
base.OnPaint(pevent);
Graphics g = pevent.Graphics;
g.SmoothingMode = SmoothingMode.AntiAlias; // 抗锯齿,使边缘平滑
RectangleF rect = new RectangleF(5, 4, (this.Height / 2) + 2, (this.Height / 2) + 2);
SolidBrush sb = new SolidBrush(Color.Red); // 默认红色
// 填充控件内部
if (this.Tag != null && this.Tag.ToString().Contains("1")) // 1为绿
{
sb = new SolidBrush(Color.Green);
}
else if (this.Tag != null && this.Tag.ToString().Contains("2")) // 2为红
{
sb = new SolidBrush(Color.Red);
}
else{
sb = new SolidBrush(Color.Yellow); // 黄
}
g.FillEllipse(sb, rect);
}
}
}
本文来自博客园,作者:꧁执笔小白꧂,转载请注明原文链接:https://www.cnblogs.com/qq2806933146xiaobai/p/17307842.html

浙公网安备 33010602011771号