Tag Archives: focus

Getting a value of a ToolStripTextBox on a lost focus

Using the Leave event does not work unless you press Tab key (which presumably takes the focus of the entire ToolStrip).

To detect the lost focus of the ToolStripTextBox use the LostFocus event. It is not in the designer and needs to be added manually, typically from the forms constructor.

public Form1()
{
   toolStripTextBox1.LostFcus += new EventHandler(toolStripTextBox1_LostFocus);
}

void toolStripTextBox1_LostFocus(object sender, EventArgs e)
{
   //Access the text property
   string value = toolStripTextBox1.Text;
}
Lastest update in May 2011, inital post in May 2011

Enabling keyboard input on Forms

By default forms do not get keyboard input.

To allow keyboard input set the forms  KeyPreview property to true.

This will enable the firing of the  KeyDown and  KeyUp events.

Lastest update in May 2011, inital post in May 2011