C#怎么填充颜色?
我在C#的窗体中画了一个三角形,怎么给它填充颜色呢?Point[]points=newPoint[3];//Apoints[0].X=(int)(a*(1+Math.Si...
我在C#的窗体中画了一个三角形,怎么给它填充颜色呢?
Point[] points = new Point[3];
//A
points[0].X = (int)(a * (1 + Math.Sin(18 * pi / 180) - Math.Cos(36 * pi / 180)));
points[0].Y = 0;
//1
points[1].X = (int)(a * (1 + Math.Sin(18 * pi / 180)));
points[1].Y = (int)(((a * (Math.Cos(36 * pi / 180) + Math.Sin(18 * pi / 180) + 1)) - (a * (1 + Math.Sin(18 * pi / 180) - Math.Cos(36 * pi / 180)))) / 2 * Math.Tan(36 * pi / 180));
//2
points[2].X = (int)(a * Math.Cos(72 * pi / 180) + a * (1 + Math.Sin(18 * pi / 180) - Math.Cos(36 * pi / 180)));
points[2].Y = (int)(a * Math.Sin(72 * pi / 180));
Graphics g1 = this.CreateGraphics();
Brush t = new SolidBrush(Color.Blue);
GraphicsPath gp = new GraphicsPath();
gp.AddLines(points);
g1.FillPath(t, gp);
这是我最终用的方法,先找到三角形的每个点的坐标,再填充。
三楼的朋友说用backcolor?我好像没找到。是不是我太笨了。 展开
Point[] points = new Point[3];
//A
points[0].X = (int)(a * (1 + Math.Sin(18 * pi / 180) - Math.Cos(36 * pi / 180)));
points[0].Y = 0;
//1
points[1].X = (int)(a * (1 + Math.Sin(18 * pi / 180)));
points[1].Y = (int)(((a * (Math.Cos(36 * pi / 180) + Math.Sin(18 * pi / 180) + 1)) - (a * (1 + Math.Sin(18 * pi / 180) - Math.Cos(36 * pi / 180)))) / 2 * Math.Tan(36 * pi / 180));
//2
points[2].X = (int)(a * Math.Cos(72 * pi / 180) + a * (1 + Math.Sin(18 * pi / 180) - Math.Cos(36 * pi / 180)));
points[2].Y = (int)(a * Math.Sin(72 * pi / 180));
Graphics g1 = this.CreateGraphics();
Brush t = new SolidBrush(Color.Blue);
GraphicsPath gp = new GraphicsPath();
gp.AddLines(points);
g1.FillPath(t, gp);
这是我最终用的方法,先找到三角形的每个点的坐标,再填充。
三楼的朋友说用backcolor?我好像没找到。是不是我太笨了。 展开
3个回答
展开全部
for( int x = 0; x < flag.Width; ++x )
{
for( int y = 0; y < flag.Height; ++y )
{
//nowColor = flag.GetPixel(x,y);
myColor = Color.FromArgb(r,g,b);
flag.SetPixel(x, y, myColor);
}
}
{
for( int y = 0; y < flag.Height; ++y )
{
//nowColor = flag.GetPixel(x,y);
myColor = Color.FromArgb(r,g,b);
flag.SetPixel(x, y, myColor);
}
}
参考资料: http://topic.csdn.net/t/20040330/17/2904735.html
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询