// 自定义控件(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);
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
作者:꧁执笔小白꧂