代码之家  ›  专栏  ›  技术社区  ›  TerribleDog

椭圆变换为矩形

  •  0
  • TerribleDog  · 技术社区  · 7 年前

    当我尝试单击“是”并接受该形状时,它将被推入形状列表

    enter image description here

    所以我需要保留它,所以我重新绘制它(使用foreach遍历形状列表/集合),使用以下方法:

    public void DrawAllShapes(object sender, PaintEventArgs e)
        {
            foreach(Shape shape in _shapes)
            {
                switch (s.type)
                {
                    case Shape.ShapeType.rectangle:
                        shape.DrawRectangle(shape.color, shape.strokeThickness, shape.points, shape.width, shape.height, e.Graphics);
                        break;
                    case Shape.ShapeType.square:
                        shape.DrawSquare(shape.color, shape.strokeThickness, shape.points, shape.width, shape.height, e.Graphics);
                        break;
                    case Shape.ShapeType.circle:
                        shape.DrawCircle(shape.color, shape.strokeThickness, shape.points, shape.width, shape.height, e.Graphics);
                        break;
                    case Shape.ShapeType.ellipse:
                        shape.DrawEllipse(shape.color, shape.strokeThickness, shape.points, shape.width, shape.height, e.Graphics);
                        break;
                    case Shape.ShapeType.triangle:
                        shape.DrawTriangle(shape.color, shape.strokeThickness, shape.tPoints.ToArray(), shape.x, shape.y, shape.width, e.Graphics);
                        break;
                }
            }
    

    }

    这就是所谓的画布绘画方法。 但这种情况会发生。椭圆被变换成矩形。

    enter image description here

    如何添加形状

        public void AcceptShape()
        {
            switch (buttons)
            {
                case Shape.ShapeType.rectangle:
                    var rect = new Shape{
                        strokeThickness = strokeRect, 
                        color = rC,
                        points = new Point((int)rX,(int)rY),
                        width = rW,
                        height = rH,
                        type = (Shape.ShapeType)System.Enum.Parse(typeof(Shape.ShapeType), "rectangle")
                    };
                    draw._shapes.Add(rect);
                    Data();
                    break;
                case Shape.ShapeType.square:
                    var square = new Shape {
                        strokeThickness = strokeSquare,
                        color = sC,
                        points = new Point((int)sX, (int)sY),
                        width = sW,
                        height = sH,
                        type = (Shape.ShapeType)System.Enum.Parse(typeof(Shape.ShapeType), "square")
                    };
                    draw._shapes.Add(square);
                    Data();
                    break;
                case Shape.ShapeType.circle:
                    var circle= new Shape {
                        strokeThickness = strokeCircle,
                        color = cC,
                        points = new Point((int)cX, (int)cY),
                        width = cW,
                        height = cH,
                        type = (Shape.ShapeType)System.Enum.Parse(typeof(Shape.ShapeType), "circle")
                    };
                    draw._shapes.Add(circle);
                    Data();
                    break;
                case Shape.ShapeType.ellipse:
                    var ellipse = new Shape {
                        strokeThickness = strokeEllipse,
                        color = eC,
                        points = new Point((int)eX, (int)eY),
                        width = eW,
                        height = eH,
                        type = (Shape.ShapeType)System.Enum.Parse(typeof(Shape.ShapeType), "ellipse")
                    };
                    draw._shapes.Add(ellipse);
                    Data();
                    break;
                case Shape.ShapeType.triangle:
                    var triangle = new Shape{
                        strokeThickness = strokeTriangle,
                        color = tC,
                        tPoints = t_Points.ToArray(),
                        x=tX,
                        y=tY,
                        width = tW,
                        type = (Shape.ShapeType)System.Enum.Parse(typeof(Shape.ShapeType), "triangle")
                    };
                    draw._shapes.Add(triangle);
                    triangleClicked = false;
                    Data();
                    break;
            }
        }
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   TerribleDog    7 年前
    foreach(Shape shape in _shapes)
            {
                switch (shape.type)
                {
                    case Shape.ShapeType.rectangle:
                        shape.DrawRectangle(shape.color, shape.strokeThickness, shape.points, shape.width, shape.height, e.Graphics);
                        break;
                    case Shape.ShapeType.square:
                        shape.DrawSquare(shape.color, shape.strokeThickness, shape.points, shape.width, shape.height, e.Graphics);
                        break;
                    case Shape.ShapeType.circle:
                        shape.DrawCircle(shape.color, shape.strokeThickness, shape.points, shape.width, shape.height, e.Graphics);
                        break;
                    case Shape.ShapeType.ellipse:
                        shape.DrawEllipse(shape.color, shape.strokeThickness, shape.points, shape.width, shape.height, e.Graphics);
                        break;
                    case Shape.ShapeType.triangle:
                        shape.DrawTriangle(shape.color, shape.strokeThickness, shape.tPoints.ToArray(), shape.x, shape.y, shape.width, e.Graphics);
                        break;
                }
            }
    

    将变量更改为switch。