CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2005
    Posts
    6

    textBox keeping focus problem

    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

  2. #2
    Join Date
    Sep 2006
    Location
    Eastern, NC, USA
    Posts
    907

    Re: textBox keeping focus problem

    Have you tried a different event such as the lostfocus event?
    Code:
            private void textBox1_LostFocus(object sender, EventArgs e)
            {
                MessageBox.Show("textbox1 lost focus", "event");
            }
    Code:
            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

  3. #3
    Join Date
    Apr 2005
    Posts
    6

    Re: textBox keeping focus problem & workaround

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured