Winforms Windows窗体中的自定义控件出现问题

Winforms Windows窗体中的自定义控件出现问题,winforms,f#,Winforms,F#,我正试着用F#写我自己的扫雷艇 我创建一种类型的按钮: type myButton(pos : Point, boum : bool, wnd : Form) = inherit Button(Parent = wnd, Bounds = Rectangle(Point((pos.X+1) * size,(pos.Y+1) * size), Size(size,size)), Visible = true,

我正试着用F#写我自己的扫雷艇

我创建一种类型的按钮:

type myButton(pos : Point, boum : bool, wnd : Form) = 
    inherit Button(Parent = wnd, 
                   Bounds = Rectangle(Point((pos.X+1) * size,(pos.Y+1) * size), Size(size,size)),
                   Visible = true,
                   Text = if boum = true then "B" else "")

    let (bomb : bool) = boum
    member this.Bomb with get() = bomb 
按钮是一种形式,我可以通过GetHildaPoint获得这些按钮。但我有一个控制按钮,而不是我的按钮,所以我不能进入现场炸弹

我怎样才能得到它?我尝试使用Tag属性,但没有成功

谢谢。

当您呼叫时,您将返回一个控件,然后您可以使用模式匹配对其进行类型测试,以查看它是否是您的自定义按钮:

let ctrl = form.GetChildAtPoint pt
match ctrl with
| :? myButton as myb ->
    let isBomb = myb.Bomb ()
    // Do something here
    ()
| _ -> () // ignore anything else

很好!非常感谢。