形状未删除

时间:2018-09-19 05:19:46

标签: c# graphics shapes

在此处,当单击“删除”按钮并单击“是”时,应将形状与行一起删除。 enter image description here

但这会发生:

enter image description here  在按钮事件之后,我已经添加了一个图片框刷新,但是仍然会发生这种情况。但是当我尝试绘制另一幅图像时,直到您绘制另一幅图像时,最后绘制的图像也不会被擦除。

代码:

import { Component, Input, OnChanges } from '@angular/core';

@Component({
  selector: 'app-event',
  templateUrl: './event.component.html',
  styleUrls: ['./event.component.css']
})
export class EventComponent implements OnChanges{

  @Input() event;

  ngOnChanges() {
    this.events$ = this.http.get("/events");
  }

}

绘制形状

这是我的绘画方式:

  

形状类

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;
        }

0 个答案:

没有答案