试图找出在TextBox中按下回车键时如何设置事件

时间:2008-12-18 19:28:57

标签: .net f# textbox

我正在玩的代码是:

open System
open System.Windows.Forms
open System.Drawing

let tehform = new Form(Text = "STOP!", Width = 200, Height = 200)
let awe = new TextBox(Left = 1, Top = 30, Width = 100)
let stuff _ _ = MessageBox.Show(awe.Text) |> ignore
let handler = new EventHandler(stuff)
let yeah = new Button(Text = "", Left = 20, Top = 60, Width = 80)
yeah.Click.AddHandler(handler)
let ms = new MenuStrip()
let file = new ToolStripDropDownButton("File")
let ddi = file.DropDownItems.Add("Hi")
ddi.Click.AddHandler(handler) |> ignore
ms.Items.Add(file) |> ignore
let dc c = (c :> Control)
tehform.Controls.AddRange([| dc yeah; dc ms; dc awe |])

我想,通过查看库,我可以使用awe.OnEnter.AddHandler(处理程序),但这也不起作用。谢谢你的帮助!

1 个答案:

答案 0 :(得分:1)

当TextBox获得焦点时,OnEnter将触发。使用OnKeyDown事件并检查事件参数的Keys属性。

Here's the MSDN documentation