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
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