当前位置: 移动技术网 > IT编程>开发语言>c# > C#画圆角矩形的方法

C#画圆角矩形的方法

2019年07月18日  | 移动技术网IT编程  | 我要评论

本文实例讲述了c#画圆角矩形的方法。分享给大家供大家参考。具体实现方法如下:

protected void page_load(object sender, eventargs e)
{
 bitmap bm = new bitmap(800, 600);
 graphics g = graphics.fromimage(bm);
 g.fillrectangle(brushes.white,new rectangle(0,0,800,600));
 fillroundrectangle(g,brushes.plum,new rectangle(100, 100, 100, 100), 8);
 drawroundrectangle(g, pens.yellow,new rectangle(100, 100, 100, 100), 8);
 bm.save(response.outputstream, imageformat.jpeg);
 g.dispose();
 bm.dispose();
}
public static void drawroundrectangle(graphics g,pen pen,rectangle rect, int cornerradius)
{
 using (graphicspath path = createroundedrectanglepath(rect, cornerradius))
 {
  g.drawpath(pen, path);
 }
}
public static void fillroundrectangle(graphics g, brush brush,rectangle rect, int cornerradius)
{
 using (graphicspath path = createroundedrectanglepath(rect, cornerradius))
 {
  g.fillpath(brush, path);
 }
}
internal static graphicspath createroundedrectanglepath(rectangle rect, int cornerradius)
{
 graphicspath roundedrect = new graphicspath();
 roundedrect.addarc(rect.x, rect.y, cornerradius * 2, cornerradius * 2, 180, 90);
 roundedrect.addline(rect.x + cornerradius, rect.y, rect.right - cornerradius * 2, rect.y);
 roundedrect.addarc(rect.x + rect.width - cornerradius * 2, rect.y, cornerradius * 2, cornerradius * 2, 270, 90);
 roundedrect.addline(rect.right, rect.y + cornerradius * 2, rect.right, rect.y + rect.height - cornerradius * 2);
 roundedrect.addarc(rect.x + rect.width - cornerradius * 2, rect.y + rect.height - cornerradius * 2, cornerradius * 2, cornerradius * 2, 0, 90);
 roundedrect.addline(rect.right - cornerradius * 2, rect.bottom, rect.x + cornerradius * 2, rect.bottom);
 roundedrect.addarc(rect.x, rect.bottom - cornerradius * 2, cornerradius * 2, cornerradius * 2, 90, 90);
 roundedrect.addline(rect.x, rect.bottom - cornerradius * 2, rect.x, rect.y + cornerradius * 2);
 roundedrect.closefigure();
 return roundedrect;
}

希望本文所述对大家的c#程序设计有所帮助。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网