Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

C# -- Form2 "CANCEL-CLOSE" button

Posted on 2009-07-15
3
Medium Priority
?
611 Views
Last Modified: 2013-12-17
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) ?
        }
0
Comment
Question by:finance_teacher
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
Pablissimo earned 2000 total points
ID: 24862491
Might have misunderstood the question, but the following for Form2's Cancel button event handler should do it:

private void button2_Click(object sender, EventArgs e)
{
  this.Close();
}

Or do you want to close Form2 from a button click on Form1?
0
 
LVL 5

Expert Comment

by:Pablissimo
ID: 24862596
As an aside, if you want to force the user to accept or cancel whatever's on Form2 before they return to Form1, try changing the

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

Author Comment

by:finance_teacher
ID: 24862657
Thanks for the GREAT help
0

Featured Post

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question