Robię projekt o nazwie "Edytor kształtu 2D" w f #. Zrobiłem ten projekt w języku C# wcześniej, więc mam wszystkie logiki, jak połączyć dwa kształty. Wiem więc, że potrzebuję listy do przechowywania wszystkich kształtów, które będę dodawać. Ale po prostu nie mogę uruchomić mojej metody addToList.Dodawanie rzeczy do listy w f #
Moja ShapeList:
let mutable ShapeList:List<RectangleZ> = [RectangleZ(100,100)]
Moje metody Add:
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
przycisk, który należy dodać prostokąty do 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
i oczywiście moim prostokąta:
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"
Element nie zostanie dodany do listy z jakiegoś powodu w żadnej z moich funkcji addToList. Moje pytanie brzmi: dlaczego?
Tak, pracowała prawidłowo! Moja lista kształtów aktualizuje teraz swoje wartości! Dziękuję Ci! –