【问题标题】:Trying to figure out how to set off an event when the enter key is pressed in a TextBox试图弄清楚在文本框中按下回车键时如何触发事件
【发布时间】:2008-12-18 19:28:56
【问题描述】:

我正在玩的代码是:

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(handler) 但这也不起作用。感谢您的帮助!

【问题讨论】:

  • 当你把你的表单称为“tehForm”时,你知道你玩的太多了。

标签: .net f# textbox


【解决方案1】:

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

Here's the MSDN documentation.

【讨论】:

    猜你喜欢
    • 2017-03-26
    • 2012-08-11
    • 2013-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多