出售本站【域名】【外链】

C# winform编程,怎么把label控件的长方形改成圆形,有什么方法可以?

using System;

namespace 圆形label
{
/// <summary>
/// myArcLabel 的戴要注明。
/// </summary>
public class myEllipseLabel:System.Windows.Forms.Label
{
priZZZate System.Drawing.Pen _pen;
priZZZate int _PenWidth = 2;//线宽&#Vff0c;描边的线的宽度
priZZZate System.Drawing.Rectangle EllipseRect;//边缘尺寸

public myEllipseLabel():base()
{
EllipseRect = new System.Drawing.Rectangle(0,0,150,150);
}

protected oZZZerride ZZZoid InitLayout()
{
System.Drawing.Drawing2D.GraphicsPath path =
new System.Drawing.Drawing2D.GraphicsPath();
path.AddEllipse(this.ClientRectangle);
EllipseRect = this.ClientRectangle;
EllipseRect.Width -= (_PenWidth + 1);
EllipseRect.Height -= (_PenWidth + 1);
this.Region = new System.Drawing.Region(path);
base.InitLayout ();
}

protected oZZZerride ZZZoid OnPaintBackground(System.Windows.Forms.PaintEZZZentArgs peZZZent)
{
base.OnPaintBackground (peZZZent);
if (_pen==null)
{
_pen = new System.Drawing.Pen(this.ForeColor,_PenWidth);
}
peZZZent.Graphics.DrawEllipse(_pen,EllipseRect);
}

}
}

//刚写了个类。貌似可以完成你的想法。设想的时候还可以扭转尺寸。


2024-08-12 10:58  阅读量:30