c# 画三角形,并填充颜色

目前知道有两种方法:画多边形、GraphicsPath。但是用画多边形的方式画三角形不太好。老画不正的,截图放大就明显了。

ExpandedBlockStart.gif 代码
1      Point point1  =   new  Point( 0 0 );
2      Point point2  =   new  Point( 11 0 );
3      Point point3  =   new  Point( 5 8 );
4      Point[] pntArr  =  {point1, point2, point3};
5 
6      e.Graphics.FillPolygon(Brushes.Red, pntArr);
7 


ExpandedBlockStart.gif 代码
 1                   int  len  =   10 ;                       
 2                   int  x  =   0 ;
 3                   int  y  =   0 ;
 4                  Point[] pntArr  =   new  Point[ 3 ];
 5                  pntArr[ 0 =   new  Point(x, y);
 6                  pntArr[ 1 =   new  Point(x  -  len, y);
 7                  pntArr[ 2 =   new  Point(x  -  len  /   2 , ( int )(len  *  Math.Sqrt( 3 /   2   +  y));
 8                  GraphicsPath path  =   new  GraphicsPath();
 9                  path.AddLines(pntArr);
10                  e.Graphics.SmoothingMode  =  System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
11                  e.Graphics.FillPath(Brushes.Red, path);               
12                  e.Graphics.SmoothingMode  =  System.Drawing.Drawing2D.SmoothingMode.Default;
13 


 

 

转载于:https://www.cnblogs.com/fireice/archive/2010/11/08/1871606.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值