Blog
    C#
    ADO.Net
    .NET
    ASP.Net & Web Forms
    Custom Controls
    Web Development
    Exception Handling
    XML
    Database
    Security in .Net
    Testing
    Web Services
    Windows Services
    Windows Controls
    WCF
    AJAX
    WPF
    XAML
    Reporting
    Setup
    VB.Net
    LINQ
    JQuery
    SilverLight
    JavaScript
    HTML5
    Crystal Report
    Cloud Computing
    Share Point
    Visual C++
    MVC
    Android
    PHP
    Java
    HTML
    WordPress
    Joomla
    Products
    Drupal
    Windows Phone
    JSON
    LightSwitch
    iPhone/iPad
    Ruby on Rails
    IIS 7
    Windows 8
    CSS/CSS3
    Excel
    MS Access
    Shortcut Keys
    Visual SourceSafe
    Team Foundation Server
    API(s)
    Sencha-Touch
    Single Page App
    Bootstrap
Follow Us
Follow _MindStick_ on Twitter View MindStick Software's LinkedIn profile View MindStick Software's Facebook profile
Top Contributor
Advertisement
Advertise with Us
Mindstick
Article Article  Forum Forum  Blog Blog  Quiz Quiz  Beginner Beginner  Careers Careers  Contact Contact  Login Login  
Home | Product | Services | About Us | Interview | DeveloperSection | Submit an Article | Submit Blog
Report Abuse Form
Reason:    
 

Home >> C# >> 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

In this Blog I am trying to explain "How to Add New Form (New Window) in C#.Net with Visual Studio 2012".
Views: 691     Comments: 0
by Vilas Shende on 9/9/2013
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".

Title :  
Comment :
Text ColorBackground Color
BoldItalicUnderline
LeftCenterRightJustify
Ordered ListBulleted List
IndentOutdent
Horizontal Rule
SubscriptSuperscript
HyperlinkImage
Design ModeDesign
View HtmlHtml
       
 
Report Abuse Form
Reason:    
 
Latest ArticleRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Latest Blogs by Vilas ShendeRSS Feed
    
    
    
    
More...
Top Viewed ArticlesRSS Feed
    
    
    
    
    
    
    
    
    
    
Top Viewed BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
Latest Interview QuestionsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Total Online Users: 5206
  
Copyright © 2009 - 2014MindStick. All Rights Reserved.