0
点赞
收藏
分享

微信扫一扫

[原创]c#自定义绘制矩形的正确姿势


public static void drawRoundRect(Graphics graphics, string solidColor, string borderColor, int x, int y, int width, int height, float radius, float bordersize)
{
GraphicsPath gpPath = new GraphicsPath();
gpPath.AddArc(x, y, radius, radius, 180, 90);//从180度 开始顺时针画90度 ,左上角
gpPath.AddArc(width - radius, y, radius, radius, 270, 90);//右上角
gpPath.AddArc(width - radius, height - radius, radius, radius, 0, 90);//右下角
gpPath.AddArc(x, height - radius, radius, radius, 90, 90);//左下角 x顺时针
gpPath.CloseAllFigures();
bool hasBorder = bordersize > 0 && borderColor != null && RegHelper.isColorValue(borderColor);
if (hasBorder)//绘制边框
{
using (Pen shadowPen = new Pen(AppUtil.parseColor(borderColor)))//清理资源的using
{
shadowPen.Alignment = PenAlignment.Inset;
shadowPen.Width = bordersize * 2;
shadowPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;//shixian
graphics.DrawPath(shadowPen, gpPath);

}

}
//绘制填充颜色。
if (!AppUtil.textIsEmpty(solidColor) && RegHelper.isColorValue(solidColor))
{
if (hasBorder)
{
width = (int)(width - bordersize);
height = (int)(height - bordersize);
x = (int)(x + bordersize);
y = (int)(y + bordersize);

}
GraphicsPath solidPath = new GraphicsPath();
if (bordersize > 2&&radius>5&&width>50)
{
radius= radius * 0.7f;
}

solidPath.AddArc(x, y, radius, radius, 180, 90);//从180度 开始顺时针画90度 ,左上角
solidPath.AddArc(width - radius, y, radius, radius, 270, 90);//右上角
solidPath.AddArc(width - radius, height - radius, radius, radius, 0, 90);//右下角
solidPath.AddArc(x, height - radius, radius, radius, 90, 90);//左下角 x顺时针
solidPath.CloseAllFigures();

SolidBrush brush = new SolidBrush(AppUtil.parseColor(solidColor));
graphics.FillPath(brush, solidPath);

}
}




[原创]c#自定义绘制矩形的正确姿势_opengl


image.png


如果画笔的方式不是insert,那么会出现一些奇怪的,情况,特别是圆角比较大的时候。​​https://docs.microsoft.com/zh-cn/dotnet/api/system.drawing.graphics?view=netframework-4.7.2​​

​​http://st233.com/blog.php?group=1​​

目前找不到方法实现的是实现 自定义按钮 阴影并且可设置阴影x,y大小,颜色,以及模糊值

举报

相关推荐

0 条评论