finance_teacher
asked on
C# -- Form2 "CANCEL-CLOSE" button
How can I get my "Form2" CANCEL button to close the form without making user's click the upper right "X" ?
-------------------------- ---------- --------
Example
1. create Form1 & Form2
2. add below code to Form1 "Open Form2" button
private void button2_Click(object sender, EventArgs e)
{
Form2 frm = new Form2();
frm.Show();
}
3. add below code to Form2 "Cancel" button
private void button2_Click(object sender, EventArgs e)
{
Form2..... (cancel or close) ?
}
--------------------------
Example
1. create Form1 & Form2
2. add below code to Form1 "Open Form2" button
private void button2_Click(object sender, EventArgs e)
{
Form2 frm = new Form2();
frm.Show();
}
3. add below code to Form2 "Cancel" button
private void button2_Click(object sender, EventArgs e)
{
Form2..... (cancel or close) ?
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the GREAT help
private void button2_Click(object sender, EventArgs e)
{
Form2 frm = new Form2();
frm.Show();
}
method in Form1 to be
private void button2_Click(object sender, EventArgs e)
{
Form2 frm = new Form2();
frm.ShowDialog(); // Note ShowDialog instead of Show
}
ShowDialog'll wait until the Form created is closed.