winform圆形标签
1,源代码
#region 圆形标签类
public class CircleLabel : Label//继承标签类 重新生成解决方案就能看见我啦
{
protected override void OnPaint(PaintEventArgs e)//重新设置控件的形状 protected 保护 override重新
{
base.OnPaint(e);//递归 每次重新都发生此方法,保证其形状为自定义形状
System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
path.AddEllipse(2, 2, this.Width - 6, this.Height - 6);
//Graphics g = e.Graphics;
//g.DrawEllipse(new Pen(Color.Red, 2), 2, 2, Width - 6, Height - 6);
Region = new Region(path);
}
}
#endregion
2,复制到窗体代码中

3,重新生成

4,设置相关属性


浙公网安备 33010602011771号