T
Tony Johansson
Hello!
This is just an example I have two forms called Form1 and Form2.
In Form1 I have the following event handler for a button called btnShowForm2
private void btnShowForm2_Click(object sender, EventArgs e)
{
Form2 frm2 = new Form2();
DialogResult dr = frm2.ShowDialog();
if (dr == DialogResult.OK)
MessageBox.Show("User clicked OK button");
else if (dr == DialogResult.Cancel)
MessageBox.Show("User clicked Cancel button");
}
In Form2 I have two buttons called OK and Cancel.
The property DialogResult is set to OK for button OK and
DialogResult is set to Cancel for button Cancel.
So when I start the application and Form1 is is shown I can click on button
btnShowForm2 which
will show Form2 with the two buttons OK and cancel.
If I click on the OK button Form2 will be closed and the message box will
display User clicked OK button and if I click the cancel button Form2 will
be closed and the messagebox will display User clicked Cancel button.
Now to my question can somebody give me a scenario when the above
functionality will be useful ?
I mean when is the point for Form1 to know that OK button is returning
DialogResult = OK in this example and
the Cancel button return DialogResult=Cancel.
How can in any way Form1 be using this information from Form2's OK button
and Cancel button
//Tony
This is just an example I have two forms called Form1 and Form2.
In Form1 I have the following event handler for a button called btnShowForm2
private void btnShowForm2_Click(object sender, EventArgs e)
{
Form2 frm2 = new Form2();
DialogResult dr = frm2.ShowDialog();
if (dr == DialogResult.OK)
MessageBox.Show("User clicked OK button");
else if (dr == DialogResult.Cancel)
MessageBox.Show("User clicked Cancel button");
}
In Form2 I have two buttons called OK and Cancel.
The property DialogResult is set to OK for button OK and
DialogResult is set to Cancel for button Cancel.
So when I start the application and Form1 is is shown I can click on button
btnShowForm2 which
will show Form2 with the two buttons OK and cancel.
If I click on the OK button Form2 will be closed and the message box will
display User clicked OK button and if I click the cancel button Form2 will
be closed and the messagebox will display User clicked Cancel button.
Now to my question can somebody give me a scenario when the above
functionality will be useful ?
I mean when is the point for Form1 to know that OK button is returning
DialogResult = OK in this example and
the Cancel button return DialogResult=Cancel.
How can in any way Form1 be using this information from Form2's OK button
and Cancel button
//Tony