努力以不同的笔触保存矩形

时间:2018-09-04 02:39:37

标签: c# graphics

我正在尝试将矩形保存到列表中,并用不同的笔触粗细重新绘制它们。实际发生的是,我可以根据需要创建多个矩形,但是这些矩形具有相同的笔触粗细。


在尝试使用新方法重新创建项目之前,我确实需要帮助。我不知道如何。

这是我的代码: 重画所有形状的Form 1 Paint Event

public void PaintAll(object sender, PaintEventArgs e)
    {
        foreach(Rectangle rects in d._rect)
        {
            foreach (Pen p in _penRect)
            {
                e.Graphics.DrawRectangle(p, rects.X, rects.Y, rects.Width, rects.Height);
            }
        }
        foreach (Rectangle squares in d._square)
        {
            foreach (Pen p in _penSquare)
            {
                e.Graphics.DrawRectangle(p, squares.X, squares.Y, squares.Width, squares.Height);
            }
        }
        foreach (Rectangle circles in d._circle)
        {
            foreach (int x in _StrokeCircle)
            {
                Pen p = new Pen(Color.Black, x);
                //Aliasing for smooth graphics when drawing and resizing
                e.Graphics.InterpolationMode = InterpolationMode.High;
                e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
                e.Graphics.DrawEllipse(p, circles.X, circles.Y, circles.Width, circles.Height);
            }
        }
        foreach (Rectangle ellipses in d._ellipse)
        {
            foreach (int x in _StrokeEllipse)
            {
                Pen p = new Pen(Color.Black, x);
                //Aliasing for smooth graphics when drawing and resizing
                e.Graphics.InterpolationMode = InterpolationMode.High;
                e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
                e.Graphics.DrawEllipse(p, ellipses.X, ellipses.Y, ellipses.Width, ellipses.Height);
            }
        }
    }

绘画班

class Draw:ShapeClass
{
    public List<Rectangle> _rect = new List<Rectangle>();
    public List<Rectangle> _square = new List<Rectangle>();
    public List<Rectangle> _circle = new List<Rectangle>();
    public List<Rectangle> _ellipse = new List<Rectangle>();
    public void DrawRectangle(PaintEventArgs e)
    {
        e.Graphics.InterpolationMode = InterpolationMode.High;
        color = new Pen(brush, Stroke);
        e.Graphics.DrawRectangle(color, new Rectangle(x, y, width, height));
    }
    public void DrawSquare(PaintEventArgs e)
    {
        e.Graphics.InterpolationMode = InterpolationMode.High;
        color = new Pen(brush, Stroke);
        e.Graphics.DrawRectangle(color, new Rectangle(x, y, width, height));
    }
    public void DrawCircle(PaintEventArgs e)
    {
        //Aliasing for smooth graphics when drawing and resizing
        e.Graphics.InterpolationMode = InterpolationMode.High;
        e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
        e.Graphics.DrawEllipse(color, new Rectangle(x,y,width,height));
    }
    public void DrawEllipse(PaintEventArgs e)
    {
        //Aliasing for smooth graphics when drawing and resizing
        e.Graphics.InterpolationMode = InterpolationMode.High;
        e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
        e.Graphics.DrawEllipse(color, new Rectangle(x, y, width, height));
    }
    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(color,tPoints);
    }
}

0 个答案:

没有答案