Windows Application - SPLessons

Win App Working With Forms

Home > Lesson > Chapter 18
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Win App Working With Forms

Windows Application Working With Forms

Closing the old form and opening a new form

shape Description

Follow the below steps to know "Closing the old form and then opening a new form".

shape Step 1

Create new windows application. Right click on the Form1.cs in the solution explorer. Then, a popup menu will appear as shown in the below figure.

shape Step 2

Select the Rename, and give the appropriate name for the form. Now, Design the form as shown in the below figure.

shape Step 3

Next, Right click on the WindowsFormsApplication in the solution explorer.  Goto Add->New Item as shown in the below figure.

shape Step 4

Then, a window will appear as shown in the below figure.

shape Step 5

Select the Windows Form, and give the name in the Name field as shown in the below figure.

shape Step 6

Then, a new form will appear in the solution explorer as shown in the below figure.

shape Step 7

Design the second form as shown in the below figure.

shape Step 8

Now, Double click on the button in the FirstForm. Then the click event will be generated. Write the following code under the button click event of FirstForm. [csharp] private void btnWelcome_Click(object sender, EventArgs e) { this.Hide();//Hides the First Form SecondForm obj = new SecondForm();// Creates an object for the second form obj.Show();// Displays the SecondForm } [/csharp]

shape Step 9

Run the application by pressing button f5 in the keyboard. The following window will appear.

shape Step 10

Click on the button shown in the above figure. Then, the First Form will be closed and a new form called Second Form will be open as shown in the below figure.