c# - 椭圆变成长方形
问题描述
当我尝试单击是并接受形状时,它会被推送到形状列表中
所以我需要保留它,所以我重绘它(使用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;
}
}
}
这在 Canvass 绘画方法中调用。但这会发生。椭圆变成了矩形。
我如何添加形状
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;
}
}
解决方案
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;
}
}
更改了要切换的变量。
推荐阅读
- python - 如果其他列 = 1,则将特定列值添加到上面的行
- mysql - 如何从表行中获取 MySQL JSON_OBJECT?
- linux - 您好,我在意外标记 `(' 附近遇到 :: 语法错误
- c++ - 使用 strcpy 后不打印字符串
- android - 检查是否在 Jenkins 或本地(Android Studio)上进行构建?
- excel - VBA 帮助:我正在寻找一次打开 7 个文件的最佳方法(上周)
- java - Android Studio Emulator 在运行项目时出现错误
- python - R Studio - 不能在 R Markdown 中使用 Python - “这个版本的 Python 是为 64 位编译的”
- sql - 查询将月份调用为列,将月份中的值总和调用为行
- c# - 获取 ComboBox 中值的 ID