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 PlayButton : ToolStripButton
{
protected override void OnPaint(PaintEventArgs pevent)
{
base.OnPaint(pevent);
Graphics g = pevent.Graphics;
g.SmoothingMode = SmoothingMode.AntiAlias; // 抗锯齿,使边缘平滑
SolidBrush sb = new SolidBrush(Color.Red); // 默认红色
RectangleF rect = new RectangleF(5, 4, (this.Height / 2) + 2, (this.Height / 2) + 2); // 圆或方形
List<PointF> pointFs = new List<PointF>();
pointFs.Add(new PointF(6,5));
pointFs.Add(new PointF(6, this.Height-5));
pointFs.Add(new PointF((this.Height / 2)+4, this.Height / 2));
// 填充控件内部
if (this.Tag != null && this.Tag.ToString().Contains("1")) // 1为绿
{
sb = new SolidBrush(Color.Red);
g.FillRectangle(sb, rect);
}
else if (this.Tag != null && this.Tag.ToString().Contains("2")) // 1为红/黄
{
sb = new SolidBrush(Color.Green);
g.FillPolygon(sb, pointFs.ToArray());
}
else
{
sb = new SolidBrush(Color.Green);
g.FillPolygon(sb, pointFs.ToArray());
}
}
}
}
标签:sb,自定义,System,Height,pointFs,new,using,Winform,图标
From: https://www.cnblogs.com/qq2806933146xiaobai/p/17307826.html