0
我寫了下面的代碼:F#不能覆蓋keyPressed事件窗口形式
open System.Windows.Forms
open System.Drawing
let f = new Form(Text="Clock", TopMost=true)
f.Show()
type Editor() =
inherit UserControl()
override this.OnMouseDown e =
printfn "Mouse Down"
override this.OnKeyDown e =
match e.KeyCode with
| Keys.W -> printfn "W pressed"
| _ -> printfn "Something else pressed"
let e = new Editor(Dock = DockStyle.Fill)
f.Controls.Add(e)
的問題是,如果我按「W」或其他隨機密鑰我得到了在控制檯上,爲何沒有消息? 對於鼠標一切工作正常。
哦,不錯,所以鍵盤事件需要焦點,而鼠標事件不? – Levenlol
顯然如此 - 雖然我不是WinForms專家! –