我正在做一個項目,您應該可以在Windows窗體環境中創建形狀。我目前有兩種不同的形狀,稱爲Circle1和Rectangle1,它們正是它們所稱的具有類似的屬性。將圖形帶到前面F#
type Rectangle1(x:int, y:int,brush1)=
let mutable thisx = x
let mutable thisy = y
let mutable thiswidth = 50
let mutable thisheight = 20
let mutable brush = brush1
member obj.x with get() = thisx and set x = thisx <- x
member oby.y with get() = thisy and set y = thisy <- y
member obj.brush1 with get() = brush and set brush1 = brush <- brush1
member obj.width with get() = thiswidth and set width = thiswidth <- width
member obj.height with get() = thisheight and set height = thisheight <- height
member obj.draw(g:Graphics) = g.FillRectangle(brush,thisx,thisy,thiswidth,thisheight)
這個矩形是可點擊和移動的,但我遇到了一個問題。我需要一些類似於c#bringToFront()方法的方法。所以當我點擊一個形狀時,我的形狀就會轉到所有其他形狀的前面。
我的存儲列表如下:
let mutable RectangleList:List<Rectangle1> = []
我用一則hitTest來確定用戶是否擊中的形狀或不:
let rec VilketObjRec (e:MouseEventArgs) (inputlist:List<Rectangle1>) =
match inputlist with
|[] -> None
|head::tail -> if (((e.X >= head.x) && (e.X <= (head.x + head.width))) && (e.Y >= head.y) && (e.Y <= (head.y+head.height)))
then Some(head) else VilketObjRec e tail
任何人有什麼樣的想法,如何解決這個問題?坦率地說,我迷路了。