Dave Hampel
Dave Hampel

Reputation: 168

How do I close a form automatically when finished?

I have form1 calling form2, which is asking for contact information. Once the form is filled in a save button is clicked. At the end of the save event, I would like form2 to close automatically returning to form1. Everything that I have found discusses closing form1, when form2 is opened. Here is the code that I use to call form2.

customer_Ship_ID = textBox_Customer_Ship_ID.Text;
using (Form Customer_Add_Contact_Form = new Customer_Add_Contact_Form(customer_Ship_ID))
{
    Customer_Add_Contact_Form.ShowDialog();
}

The entire save event works perfectly and the user is finished. If the form would just close without clicking the 'X' in the upper right corner of the form, that would be great.

Upvotes: 0

Views: 120

Answers (2)

Uzair Ahmed Siddiqui
Uzair Ahmed Siddiqui

Reputation: 364

use this.Close() at the end of your save event.

Upvotes: 2

tickwave
tickwave

Reputation: 3445

Use this.Close() or formName.Close() after your Save event.

Upvotes: 3

Related Questions