// 圆角代码 第一个参数是该元素的宽,第二个参数是元素的高,第三个参数是圆角半径
public Region Round(int width, int height, int _Radius)
{
System.Drawing.Drawing2D.GraphicsPath oPath = new System.Drawing.Drawing2D.GraphicsPath();
int x = 1;
int y = 1;
int thisWidth = width;
int thisHeight = height;
int angle = _Radius;
if (angle > 0)
{
System.Drawing.Graphics g = CreateGraphics();
oPath.AddArc(x, y, angle, angle, 180, 90); // 左上角
oPath.AddArc(thisWidth - angle, y, angle, angle, 270, 90); // 右上角
oPath.AddArc(thisWidth - angle, thisHeight - angle, angle, angle, 0, 90); // 右下角
oPath.AddArc(x, thisHeight - angle, angle, angle, 90, 90); // 左下角
oPath.CloseAllFigures();
return(new System.Drawing.Region(oPath));
}
// -----------------------------------------------------------------------------------------------
else
{
oPath.AddLine(x + angle, y, thisWidth - angle, y); // 顶端
oPath.AddLine(thisWidth, y + angle, thisWidth, thisHeight - angle); // 右边
oPath.AddLine(thisWidth - angle, thisHeight, x + angle, thisHeight); // 底边
oPath.AddLine(x, y + angle, x, thisHeight - angle); // 左边
oPath.CloseAllFigures();
return(new System.Drawing.Region(oPath));
}
}