保存三角形以重绘C#

时间:2018-09-05 06:10:28

标签: c# graphics

我想保存将矩形绘制到列表中所需的所有点,以便能够绘制另一个三角形并保留前一个三角形。我通过将它们保存在

中来对其他形状(例如矩形等)进行了此处理
List< Rectangle > _rect = new List< Rectangle >

并使用

遍历它们
foreach(Rects rect in _rect)

关于三角形该怎么办?

    public PointF[] tPoints { get; set; }

    public void DrawTriangle(PaintEventArgs e)
    {
        tPoints = new PointF[3];
        float angle = 0;
        tPoints[0].X = x;
        tPoints[0].Y = y;
        tPoints[1].X = (float)(x + width * Math.Cos(angle));
        tPoints[1].Y = (float)(y + width * Math.Sin(angle));
        tPoints[2].X = (float)(x + width * Math.Cos(angle - Math.PI / 3));
        tPoints[2].Y = (float)(y + width * Math.Sin(angle - Math.PI / 3));

        e.Graphics.InterpolationMode = InterpolationMode.High;
        e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
        e.Graphics.DrawPolygon(new Pen(color, strokeThickness), tPoints);
    }

1 个答案:

答案 0 :(得分:0)

您可以自己创建这样的数据类型!

systemctl enable myservice.service

然后您可以创建它的列表:

struct Triangle {
    // all your need for a triangle is three points, isn't it?
    public Point PointA { get; }
    public Point PointB { get; }
    public Point PointC { get; }

    public Triangle(Point a, Point b, Point c) {
        PointA = a;
        PointB = b;
        PointC = c;
    }
}