Борьба за спасение прямоугольника с другим ходом - PullRequest
0 голосов
/ 04 сентября 2018

Я пытаюсь сохранить прямоугольники в списке и перекрасить их с разной толщиной штрихов. На самом деле происходит то, что я могу создавать много прямоугольников столько, сколько хочу, но эти прямоугольники имеют одинаковую толщину обводки.


Мне действительно нужна помощь, прежде чем я попытаюсь воссоздать проект с новым подходом. Понятия не имею, как.

Вот мой код: Событие рисования формы 1, когда оно перерисовывает все фигуры

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);
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...