none
Textbox on a form not firing a Leave event when clicking on another form RRS feed

  • Question

  • I have a main form that has a menu strip and that also is composed of many other forms.

    I offer Settings using a  pop-up form(to be exact, DockContent or Dialog) that can be opened via the menu strip on the main form.

    The Settings form has a Textbox whose content needs to be validated.

    The leave event on that Textbox fires perfectly fine if I click on all other controls on the pop-up Settings form.

    But it does not fire if I click on outside the Settings form.

    Does anyone know what this is about and how to go about resolving this?

    Regards,

    Wednesday, April 17, 2019 9:48 PM

All replies

  • Try another event: LostFocus. It can be added inside the Load event of Settings form. In C#:

     

    textBox1.LostFocus += TextBox1_LostFocus;

     

    . . .

     

    private void TextBox1_LostFocus( object sender, EventArgs e )

    {

       . . .

    }

     


    Thursday, April 18, 2019 6:09 AM
  • Hi JamesRockStar,

    Thank you for posting here.

    For your question, if you want to capture the mouse click in the Settings form, MouseDown event is a easy way.

       private void Form1_MouseDown(object sender, MouseEventArgs e)
            {
                if (e.Location.X != textBox1.Location.X && e.Location.Y != textBox1.Location.Y)
                {
                    MessageBox.Show("Hello");
                }
            }

    If you want to capture the mouse click outside the form, you could download the source file from the code project about the Global Mouse Hooks.

    https://www.codeproject.com/Articles/7294/Processing-Global-Mouse-and-Keyboard-Hooks-in-C

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, April 18, 2019 7:16 AM
    Moderator