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

Write a comment

I appreciate comments, suggestions, compliments etc. Unfortunately I have no time to reply to them. Useful input will be used for sure!