// 自定义控件(ToolStripButton)
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); // 默认红色
string color = this.Tag == null ? string.Empty : this.Tag.ToString(); // 颜色
// 填充控件内部
if (color.Contains("绿")) // 绿
{
sb = new SolidBrush(Color.Green);
}
else if (color.Contains("黄")) // 黄
{
sb = new SolidBrush(Color.Green);
}
else if (color.Contains("红")) // 红
{
sb = new SolidBrush(Color.Green);
}
g.FillEllipse(sb, rect);
}
}
标签:color,ToolStripButton,Color,sb,new,红黄绿,SolidBrush,Winform
From: https://www.cnblogs.com/qq2806933146xiaobai/p/17235970.html