使用C#中的图形的多边形 [英] Polygon using graphics in C#
本文介绍了使用C#中的图形的多边形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我创建多边形的代码。
我被要求绘制偏移多边形。
如果用户在文本框中输入50,那么多边形应该是随着输入的扩展绘制
各方面。
这是我的代码
Here is my code to create polygon.
I was asked to draw an offset polygon.
If a user enters "50" in text box then a polygon should be drawn with extension of input
in all sides.
Here is my code
Brush drawing_brush = new SolidBrush(Color.Red);
Brush drawing_brush1 = new SolidBrush(Color.Blue);
//Creating Pen
Pen drawing_pen = new Pen(drawing_brush, 2);
Pen drawing_pen1 = new Pen(drawing_brush1, 2);
// Initiating Graphics
Graphics Draw = this.CreateGraphics();
//int x=300;
//int y=300;
int x = Convert.ToInt32(Width.Text);
int y = Convert.ToInt32(Height.Text);
//Points Initialization
Point P1 = new Point(x, y);
Point P2 = new Point(x + 100, y);
Point P3 = new Point(x + 100, y + 100);
Point P4 = new Point(x, y + 100);
Point[] P = { P1, P2, P3, P4 };
Draw.DrawPolygon(drawing_pen, P);
Point Q1 = new Point(x - 10, y - 10);
Point Q2 = new Point(x + 110, y - 10);
Point Q3 = new Point(x + 110, y + 110);
Point Q4 = new Point(x - 10, y + 110);
Point[] Q = { Q1, Q2, Q3, Q4 };
Draw.DrawPolygon(drawing_pen1, Q);
推荐答案
你可以参考这个
绘图根据对所述输入一个多边形-坐标一> [ ^ ]
You can refer this
drawing-a-polygon-according-to-the-input-coordinates[^]
是的,例如, Graphics
类提供 DrawPolygon [ ^ ]方法。您可以要求用户输入所需的点,然后使用此方法执行任务。
Yes, for instance, the Graphics
class provides the DrawPolygon[^] method. You could ask the user to input the required points and then use such method to perform the task.
这篇关于使用C#中的图形的多边形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文