我正在做一个项目,您应该可以在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
任何人有什么样的想法,如何解决这个问题?坦率地说,我迷路了。