我正在做一个名为“2D形状编辑器”的项目在f#中。我之前在c#中完成了这个项目,所以我已经掌握了关于如何连接两个形状的所有逻辑。所以我知道我需要一个列表来保存我将要添加的所有形状。但我根本无法让我的addToList方法工作。将东西添加到f中的列表中#
我ShapeList:
let mutable ShapeList:List<RectangleZ> = [RectangleZ(100,100)]
我的添加方法:
let addToList (listan:List<RectangleZ>) (element:RectangleZ) = let ShapeList = [email protected][element] in ShapeList
//Method to add into the ShapeList
let addToList (listan:List<RectangleZ>) (element:RectangleZ) = element::ShapeList
//Other try on adding into shapeList
应添加矩形到ShapeList按钮:
btn.Click.Add(fun _ -> new RectangleZ(500, 100) |> addToList ShapeList |>ignore |> saver)
//Button click method that should be adding the RectangleZ(500, 100) to my ShapeList
而且ofcourse我矩形:
type RectangleZ(x:int, y:int)=
let mutable thisx = x
let mutable thisy = y
let mutable thiswidth = 50
let mutable thisheight = 20
let brush = new SolidBrush(Color.Black)
member obj.x with get() = thisx and set x = thisx <- x
member obj.y with get() = thisy and set y = thisy <- y
member obj.width with get() = thiswidth and set width = thiswidth <- width
member obj.height with get() = thisheight and set height = thisheight <- height
member obj.thisColor = Color.FromArgb(167, 198, 253)
member obj.draw(paper:Graphics) = paper.FillRectangle(brush, thisx, thisy, 50, 20)
member obj.ShapeType = "Rectangle"
在我的addToList函数中,元素dosn't因某种原因被添加到列表中。我的问题是为什么?
是的,正确的工作!我的ShapeList现在更新它的值!谢谢! –