I have inherited a complex application with dozens of controls.
The new functionality I am to surgically insert is to prevent the user
from proceeding further if any of the data is incorrect in my control
on the current page.
I can capture the .Leave event from my control, but I do not want
Windows to honor the destination control that the user clicked. Is
there such a way to tell Windows to CancelEvents and do not activate
the control that the user clicked?
If there were, this method would be something like:
System.Windows.Forms.Application.CancelEvents(), instead of:
System.Windows.Forms.Application.DoEvents()
Thanks.
Gilles Kohl [MVP] - 24 Mar 2008 10:11 GMT
>I have inherited a complex application with dozens of controls.
>
[quoted text clipped - 14 lines]
>
>Thanks.
Not sure if you are _providing_ controls, or using existing ones.
If the latter, have you considered handling the "Validating" event of the
control?
http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.validating.aspx
(Specifically have a look at the example in there - it prevents focus from
moving away from a textbox if the entered text does not look like an email.)
If the former, overriding OnValidating and adding your own custom validation
(after calling the base class's OnValidating method so that registered
delegates receive the event) could be the way to go.
Regards,
Gilles.