加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

ASP.NET C#图形路径形状

发布时间:2020-12-16 09:36:13 所属栏目:asp.Net 来源:网络整理
导读:我在为略微修改的圆角矩形生成某个路径时遇到问题.这是我用于生成圆角矩形的代码: public static System.Drawing.Drawing2D.GraphicsPath RoundedRectangle(Rectangle r,int d) { System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D
我在为略微修改的圆角矩形生成某个路径时遇到问题.这是我用于生成圆角矩形的代码:

public static System.Drawing.Drawing2D.GraphicsPath RoundedRectangle(Rectangle r,int d)
    {

        System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();

        gp.AddArc(r.X,r.Y,d,180,90);
        gp.AddArc(r.X + r.Width - d,270,r.Y + r.Height - d,90);
        gp.AddArc(r.X,90,90);
        gp.AddLine(r.X,r.X,r.Y + d / 2);

        return gp;
    }

现在我需要生成这样的东西:

实现这一目标的最佳方法是什么?也许通过擦除左边框然后以某种方式添加直角三角形?

任何帮助表示赞赏,谢谢!

解决方法

看看这会对你有所帮助.

public void DrawRoundRect(Graphics g,Pen p,float x,float y,float width,float height,float radius)
{
GraphicsPath gp = new  GraphicsPath();

gp.AddLine(x + radius,y,x + width - (radius * 2),y); // Line
gp.AddArc(x + width - (radius * 2),radius * 2,90); // Corner
gp.AddLine(x + width,y + radius,x + width,y + height - (radius * 2)); // Line
gp.AddArc(x + width - (radius * 2),y + height - (radius * 2),90); // Corner
gp.AddLine(x + width - (radius * 2),y + height,x + radius,y + height); // Line
gp.AddArc(x,90); // Corner
gp.AddLine(x,x,y + radius); // Line
gp.AddArc(x,90); // Corner
gp.CloseFigure();

g.DrawPath(p,gp);
gp.Dispose();

}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读