[转]c# 画圆角矩形

本文转自:http://www.cnblogs.com/xujh/archive/2008/05/12/717433.htmlprotectedvoidpage_load(objectsender,eventargse){bitmapbm=newbitmap(800,600);graphicsg=graphics.fromimage(bm);g.fillrectangle(brushes.white,newrectangle(0,0,800,600));fillroundrectangle(g,brushes.plum,newrectangle(100,100,100,100),8);drawroundrectangle(g,pens.yellow,newrectangle(100,100,100,100),8);bm.save(response.outputstream,imageformat.jpeg);g.dispose();bm.dispose();}publicstaticvoiddrawroundrectangle(graphicsg,penpen,rectanglerect,intcornerradius){using(graphicspathpath=createroundedrectanglepath(rect,cornerradius)){g.drawpath(pen,path);}}publicstaticvoidfillroundrectangle(graphicsg,brushbrush,rectanglerect,intcornerradius){using(graphicspathpath=createroundedrectanglepath(rect,cornerradius)){g.fillpath(brush,path);}}internalstaticgraphicspathcreateroundedrectanglepath(rectanglerect,intcornerradius){graphicspathroundedrect=newgraphicspath();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();returnroundedrect;}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值