Trying to figure out how to set an event when the enter key is pressed in a textbox

The code I'm playing with is:

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 |])

      

I thought after looking at the library I could use awe.OnEnter.AddHandler (handler), but that didn't work either. Thanks for the help!

+1


source to share


1 answer


OnEnter is fired when the TextBox receives focus. Use the OnKeyDown event and check the Keys property of the args events.



Here's the MSDN documentation .

+1


source







All Articles