G
Guest
I have a Form containing a Label (Label1), a TextBox (TextBox1), and a
UserControl itself containing a Label (Label2) and a TextBox (TextBox2).
There is an event handler for the Validating event of TextBox1, which checks
whether the TextBox contains a valid value and, if not, displays a message
box and sets the Cancel property of the CancelEventArgs to True.
If the user enters an invalid value in TextBox1 and then clicks on TextBox2,
the Validating event handler is executed, the message box is displayed, and
focus stays on TextBox1 as expected.
If the user enters an invalid value in TextBox1 and then clicks on the
background of the UserControl (anywhere in the UserControl but outside Label2
and TextBox2), the Validating event handler is executed twice, and therefore
the message box is displayed twice before focus is returned to TextBox1,
which does not seem normal to me.
Does anybody understand the reason for this behaviour and how I could
prevent the same message box being displayed twice to the user?
Thanks in advance.
UserControl itself containing a Label (Label2) and a TextBox (TextBox2).
There is an event handler for the Validating event of TextBox1, which checks
whether the TextBox contains a valid value and, if not, displays a message
box and sets the Cancel property of the CancelEventArgs to True.
If the user enters an invalid value in TextBox1 and then clicks on TextBox2,
the Validating event handler is executed, the message box is displayed, and
focus stays on TextBox1 as expected.
If the user enters an invalid value in TextBox1 and then clicks on the
background of the UserControl (anywhere in the UserControl but outside Label2
and TextBox2), the Validating event handler is executed twice, and therefore
the message box is displayed twice before focus is returned to TextBox1,
which does not seem normal to me.
Does anybody understand the reason for this behaviour and how I could
prevent the same message box being displayed twice to the user?
Thanks in advance.