Форма не стирается - PullRequest
       3

Форма не стирается

0 голосов
/ 19 сентября 2018

Здесь, когда нажимаете кнопку «Удалить» и нажимаете «Да», фигура должна быть удалена вместе со строкой.enter image description here

Но это происходит:

enter image description here Я уже добавил обновление Picturebox после событий кнопки, но это все еще происходит.Но когда я пытаюсь нарисовать другое изображение, последнее нарисованное изображение также не будет удалено, пока вы не нарисуете другое.

Код:

private void btn_Delete_Click(object sender, EventArgs e)
    {
        DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete the Shape?", "Delete", MessageBoxButtons.YesNo);
        if (dialogResult == DialogResult.Yes)
        {
            string type = (string)dgv_Layers.CurrentRow.Cells[1].Value;
            int index = (int)dgv_Layers.CurrentRow.Cells[0].Value;
            //MessageBox.Show(index.ToString());
            if(type == "R" || type == "S")
            {
                draw._rectangles.RemoveAt(index-1);
                dgv_Layers.Rows.RemoveAt(index-1);
                counter--;
            }
            else if (type == "C" || type == "E")
            {
                draw._circles.RemoveAt(index - 1);
                dgv_Layers.Rows.RemoveAt(index - 1);
                counter--;
            }
            else if(type == "T")
            {
                draw._triangle.RemoveAt(index - 1);
                dgv_Layers.Rows.RemoveAt(index - 1);
                counter--;
            }
            for (int i = 0; i < dgv_Layers.Rows.Count; i++)
            {
                dgv_Layers.Rows[i].Cells[0].Value = i + 1;
            }

            pictureBox_Canvass.Refresh();
        }
        else if (dialogResult == DialogResult.No)
        {
            return;
        }
    }

Рисование фигуры

Вот как я рисую:

Класс формы

    public void DrawRectangle(Color c, int stroke, PointF points, float w, float h,Graphics g)
    {
        this.points = points;
        this.width = w;
        this.height = h;
        this.strokeThickness = stroke;

        //Aliasing for smooth graphics when drawing and resizing
        g.InterpolationMode = InterpolationMode.High;
        g.SmoothingMode = SmoothingMode.HighSpeed;
        g.DrawRectangle(new Pen(c,stroke), points.X, points.Y,w,h);
    }

Основная форма

public void DrawRect()
    {
        rW = (Convert.ToInt32((Convert.ToInt32(tbox_Width.Text) * 96) / 25.4));
        rH = (Convert.ToInt32((Convert.ToInt32(tbox_Height.Text) * 96) / 25.4));
        rX = (s.center.X - (rW / 2));
        rY = (s.center.Y - (rH / 2));
        strokeRect = trackBar_Stroke.Value;
        rC = Color.Red;
    }

    private void pictureBox_Canvass_Paint(object sender, PaintEventArgs e)
    {
      switch (buttons)
        {
            case Shape.ShapeType.rectangle:
                s.DrawRectangle(rC, strokeRect, new PointF(rX, rY), rW, rH, e.Graphics);
                break;
            case Shape.ShapeType.square:
                s.DrawSquare(sC, strokeSquare, new PointF(sX, sY), sW, sH, e.Graphics);
                break;
            case Shape.ShapeType.circle:
                s.DrawCircle(cC, strokeCircle, new PointF(cX, cY), cW, cH, e.Graphics);
                break;
            case Shape.ShapeType.ellipse:
                s.DrawEllipse(eC, strokeEllipse, new PointF(eX, eY), eW, eH, e.Graphics);
                break;
            case Shape.ShapeType.triangle:
                s.DrawTriangle(tC, strokeTriangle, t_Points, tX, tY, tW, e.Graphics);
                break;
        }

}

Как я их всех рисую

public void DrawAllShapes(object sender, PaintEventArgs e)
    {
        if(_rectangles.Count == 0 && _circles.Count == 0 && _triangle.Count == 0)
        {
            ClearCanvass(sender, e);
            ShowGrid(sender, e);
        }
        else
        {
            foreach (Shape shape in _rectangles)
            {
                shape.DrawRectangle(shape.color, shape.strokeThickness, shape.points, shape.width, shape.height, e.Graphics);
                shape.DrawSquare(shape.color, shape.strokeThickness, shape.points, shape.width, shape.height, e.Graphics);
            }
            foreach (Shape shape in _circles)
            {
                shape.DrawCircle(shape.color, shape.strokeThickness, shape.points, shape.width, shape.height, e.Graphics);
                shape.DrawEllipse(shape.color, shape.strokeThickness, shape.points, shape.width, shape.height, e.Graphics);
            }
            foreach (Shape shapes3 in _triangle)
            {
                shapes3.DrawTriangle(shapes3.color, shapes3.strokeThickness, shapes3.tPoints.ToArray(), shapes3.x, shapes3.y, shapes3.width, e.Graphics);
            }
        }

    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...