StrataFrame Forum

How do I bypass the validation if the user clicks to CLOSE the form while the cursor is in the textbox?

http://forum.strataframe.net/Topic32226.aspx

By Ross L Rooker, Sr.(1) - 10/15/2013

MicroFour.StrataFrame.UI.Windows.Forms.Infragistics.UltraMaskedEdit textbox with validation code in the LEAVE event. How do I bypass the validation if the user clicks to CLOSE the form while the cursor is in the textbox?
By StrataFrame Team - 10/15/2013

If the Leave event fires before the Closing event of the form, then I'm not sure there is a clean way to do it.  I could see doing your validation on a timer and when the Closing event fires, it cancels the timer if it's started, but that would be kind of jicky.  When the leave event fires, can you obtain the reference to the control that has the next focus?  If so, then you might be able to detect whether the chrome has focus and the form is closing.  
By Edhy Rijo - 10/15/2013

Hi Ross,

Don't know if this would work because I have not tried, but here it goes anyway....

  1. Create a Private variable in your form, something like Private _FormIsClosing as Boolean = False
  2. In the FormClosing() event, set _FormIsClosing = True
  3. Move your validation code to the UltraMaskedEdit.AfterExitEditMode() instead of the UltraMaskedEdit.Leave() because the Leave() event will not fired after the FormClosing() event
  4. In the UltraMaskedEdit.AfterExitEditMode() event test for _FormIsClosing = True as part of your validation.
Hope this work for you!!!