PUZZLE: DialogResult behaves wierd
Posted on 2004-08-19
Easy Demo: just cut and paste...
DialogResult seems to behave differently within the context of a program, and within the context of a program afte the program has caused a fatal error....
Try this out. Its simple cut and paste.... Just create a new vb.net windows app...
Set Main as the startup object and add the following code to a new module...
On Form2, put some button, and when you click on that button,
raise an exception: Throw New Exception("xxx") <-- click event of the button....
Run the program and click on the button...
Public sub Main()
dim s as Form1
s = new Form1
s = nothing
Catch ex as exception
dim sdb as new SaveDialogBox
dim DR as DialogResult
DR = sdb.ShowDialog '<-- Choose a file that already exists and hit save...
Messagebox.show(DR) '<-- Shows '2' meaning Cancel, even if you selected to save
The first observation, as mentioned in the code comments is that if you choose save on a file that already exists, then DialogResult equals cancel.
The second observation is that if you choose a file that already exists, and the dialog result box tells you "Hey, buddy, thsi file already exists", and then you hit the cancel button, Dialog result box is not suppose to exit. It is suppose to continue to let you choose another file. That's exactly how it behaves, unless the dialog box is a part of code that has been caught due to try...catch...
IS THIS A MICROSOFT BUG OR AM I DOING SOMETHING WRONG?