none
Lost focus on textbox in user Control.... RRS feed

  • Question

  • Hi!

    I've created a user control which contains a textbox. How do i, in the code of the user control, capture when the textbox loose focus?

    Cause it does not fire the  private void Note_text_Leave(object sender, EventArgs e), when i click like for an example the desktop or anywhere outside my application.

    Is this possible?
    Friday, October 17, 2008 10:21 AM

Answers

  • In the code , you can add this after InitializeComponent

     

    textBox1.LostFocus += new EventHandler(textBox1_LostFocus);

     

    Then implement it as :

     

    void textBox1_LostFocus(object sender, EventArgs e)

    {

     // Your code

    }

    Friday, October 17, 2008 12:43 PM

All replies

  • Doesnt the LostFocus Event fire when the focus is lost did u check it?

    Friday, October 17, 2008 12:38 PM
  • Wheres the lost focus event? Or how do i implement it?
    Friday, October 17, 2008 12:39 PM
  • In the code , you can add this after InitializeComponent

     

    textBox1.LostFocus += new EventHandler(textBox1_LostFocus);

     

    Then implement it as :

     

    void textBox1_LostFocus(object sender, EventArgs e)

    {

     // Your code

    }

    Friday, October 17, 2008 12:43 PM
  • That's not how it works, the text box is still the active control and it will have the focus when the user activates the form again.  You'll need to resolve this with the UserControl owner's Form.Deactivate event.  It could, for example, call a public method in your UC like Activate(bool).
    Friday, October 17, 2008 12:49 PM
    Moderator