Home > DeveloperSection > Blogs > How to Add New Form (New Window) in C#.Net with Visual Studio 2012

How to Add New Form (New Window) in C#.Net with Visual Studio 2012

Posted by  Vilas Shende
on    September-09-2013 21:21 PM

C# C# 
Ratings:
0 Comment(s)
 844  View(s)
Rate this:
In this Blog I am trying to explain "How to Add New Form (New Window) in C#.Net with Visual Studio 2012".

Open Visual Studio 2012


Create New Project

Select Language "Visual C#", Select Application Type "Windows Form Application" & click on OK button.

You will get blank Form as shown below.

Add Button control on form
*How to add Button Control?
You will see Toolbox at lest side of opened blank Form, if Toolbox not visible at lest side of the bank form then Go to Menu Bar > View > Toolbox OR you can open using shortcut key "Ctrl + Alt + X"

There are 3 options to add Button control on form (may be more)
a) Drag & Drop Button control from Toolbox OR
b) Single click on Button control then single click on Form OR
c) Double click on Button control.

After adding Button Control, you can re-size, rename it, I have renamed it as "Open New Form". Now your form will look like below given image.


Now Add New Item.
*How to Add New Item?
Go to Menu Bar > Project > Add New Item OR use shortcut key "Ctrl + Shift + A", you will get long list of items, you have to choose "Windows Form" as shown in following image then click to Add button.

Now you are having two forms. i.e. Form1 (First Window) & Form2 (Second Window). 
Return to Form1 where we added Button Control To Open New Form (New Window).
Double Click on Button Control, You will see code section (code window) as given below.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace New_Project
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        
        private void button1_Click(object sender, EventArgs e)
        {

        }
    }
}

Write the code for linking Second Form with Button control.

*Which/What code I have to write & Where to Write?
You have to Write This Code

Form2 VILAS = new Form2();
            VILAS.Show(); 

Above code should be in-between Button control click event, that mean your final code will look like this
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace New_Project
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        
        private void button1_Click(object sender, EventArgs e)
        {
               Form2 VILAS = new Form2();
               VILAS.Show(); 
        }
    }
}

Build your code & run it.

*How to Build?
Go to Menu Bar > Build > Build New Project.
Congrats, your little Project has been finished now.

Now check & Run your project?
*How to check & Run?
Go to Menu Bar > Debug Start Debugging OR Press "F5" Button to run. Your first Form (First window) will appear with button Control, Now Press Button "Open New Form", Exactly you will get your Second Form (Second Window).




Thanks, I hope this blog will help you to understand "How to Add New Form OR How to Open New Window from Exist one".