Canceling the Load Form event in .NET
I was trying to find a way not to load a form when some error condition occured.
Briefly, the whole cancel logic should be placed in the constructor of the form and an exception should be thrown whenever canceling is necessary. The Show or ShowDialog methods must be included in the same try-catch block as the constructor.
Thus, when the exception is thrown, no form is displayed. There is no reliable way of canceling the Load event from within the Load event handler : if you call Close( ), you get an exception of the type : “Cannot acces a disposed object” on the Show or ShowDialog form methods.
See the following discussion also :
http://discuss.fogcreek.com/dotnetquestions/default.asp?cmd=show&ixPost=1286.
-
Archives
- May 2009 (1)
- April 2009 (4)
- February 2008 (1)
- November 2007 (1)
- August 2007 (1)
- July 2007 (2)
- June 2007 (2)
- May 2007 (1)
-
Categories
-
RSS
Entries RSS
Comments RSS
