using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace JackLib.GdiHelper {
/// <summary>
/// GdiHelper
/// </summary>
public class GdiHelper {
/// <summary>
/// 获取圆角矩形
/// </summary>
/// <param name="rect">原始矩形</param>
/// <param name="radius">圆角大小(像素)</param>
/// <returns></returns>
public static GraphicsPath GetRoundRectangle(Rectangle rect, int radius) {
GraphicsPath path = new GraphicsPath();
Point lefttop = new Point(rect.X, rect.Y);
Point righttop = new Point(rect.X + rect.Width, rect.Y);
Point rightbottom = new Point(rect.X + rect.Width, rect.Y + rect.Height);
Point leftbottom = new Point(rect.X, rect.Y + rect.Height);
path.AddArc(lefttop.X, lefttop.Y, radius * 2, radius * 2, 180, 90);
path.AddLine(lefttop.X + radius, lefttop.Y, righttop.X - radius, righttop.Y);
path.AddArc(righttop.X - radius * 2, righttop.Y, radius * 2, radius * 2, 270, 90);
path.AddLine(righttop.X, righttop.Y + radius, rightbottom.X, rightbottom.Y - radius);
path.AddArc(rightbottom.X - radius * 2, rightbottom.Y - radius * 2, radius * 2, radius * 2, 0, 90);
path.AddLine(rightbottom.X - radius, rightbottom.Y, leftbottom.X + 5, leftbottom.Y);
path.AddArc(leftbottom.X, leftbottom.Y - radius * 2, radius * 2, radius * 2, 90, 90);
path.AddLine(lefttop.X, leftbottom.Y - radius, lefttop.X, lefttop.Y + radius);
path.CloseFigure();
return path;
}
}
}