Click to See Complete Forum and Search --> : textBox keeping focus problem
werner.keilholz
December 4th, 2006, 09:46 AM
I have a form with a bunch of textBox'es in it.
The Leave events of these textBoxes are executes as one would expect if the user pushes the TAB key, clicks on the next box, etc.
However, if one chooses a menuItem, the current textBox keeps the focus and the Leave event does not happen.
Did anyone else see this phenomenon ? Any ideas how to force the event to happen ?
Thanks in advance,
Werner
petes1234
December 4th, 2006, 11:23 PM
Have you tried a different event such as the lostfocus event?
private void textBox1_LostFocus(object sender, EventArgs e)
{
MessageBox.Show("textbox1 lost focus", "event");
}
private void Form9_Load(object sender, EventArgs e)
{
this.textBox1.LostFocus += new System.EventHandler(this.textBox1_LostFocus);
}
In my playing with this, it seems to work if the menu item has a method attached to its click event. Otherwise the textbox will not lose focus.
Let me know if this works, and good luck!
/Pete
werner.keilholz
December 5th, 2006, 04:06 AM
Thanks Pete for your suggestion. I tried both the Leave and LostFocus events, but none is triggered (in my IDE, VS 2005, 8.0, the LostFocus event is not proposed in the properties of a textBox, I had to add it by hand).
But your suggestion gave me another idea: in the menuItems Click Event, I just set focus explicitly to some other control (the button corresponding to the menu item, in my case):
private void menuItem6_Click(object sender, System.EventArgs e)
{
button2.Focus();
...
}
I finally pinned it down like that, and you help me find this workaround - thanks !
Werner
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.