DialogResult at Closing event

C

Compulim

Hi,

I am writing a two-form application, where the first form will popups the
second form. The second form's minimize button is disabled (OK button shown
on upper right).

Whenever a user close the second form, the form fires the "Closing" event.
The "Closing" event handler will change the form's DialogResult to
DialogResult.Cancel.

But in the first form, it caught DialogResult.OK instead of
DialogResult.Cancel.

The code fragment looks like this:

class Form1 {
public Form1() {
DialogResult dr;

dr = new Form2().ShowDialog();

Console.WriteLine( dr.ToString() ); // this one returns
DialogResult.OK instead of DialogResult.Cancel
}
}

class Form2 {
public Form2() {
this.Closing += new CancelEventHandler( Form2_Closing );
this.MinimizeBox = false;
}

private void Form2_Closing(object sender,
System.ComponentModel.CancelEventArgs e) {
this.DialogResult = DialogResult.Cancel;
}
}

If the close event is NOT fired by clicking the upper-right OK button (e.g.
making a close button), DialogResult.Cancel can be returned.

Is there anyway to return DialogResult.Cancel after clicking the upper-right
OK button?


Compulim @ kasuei
 
P

Peter Foot [MVP]

I think this is because on Pocket PC forms shown with ShowDialog use the Ok
button which returns the Ok dialog result. Therefore if you want to provide
a positive response for some other method of closing the dialog use another
DialogResult - e.g. DialogResult.Yes and then use this in your other form to
determine when the form was dismissed with the Ok button and when another
action closes the dialog.

Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.opennetcf.org

Do have an opinion on the effectiveness of Microsoft Windows Mobile and
Embedded newsgroups? Let us know!
https://www.windowsembeddedeval.com/community/newsgroups
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top