Windows Application using Notepad

Open notepad, write the following code in it, save, compile and then execute

using System;
using System.Windows.Forms;
public class Form1 : Form {
	static void Main() {
		Form1 f = new Form1();
		Application.Run(f);
	}
}

Windows Applications using Visual Studio

To develop a windows application under VS open the new project window, select "Windows Forms Application" project template and specify a name to the project

  • Form1
  • Program
  • Form1 is the class which is defined inheriting from predefined class Form, e.g.: public partial class Form1 : Form Here the class Form1 is partial which means it is defined on multiple files

  • Form1.cs
  • Form1.Designer.cs

  • Program is a static class and in this class we find a Main method under which object of class Form1 is created for execution, as following:

     Application.Run(new Form1());
    

    Windows applications developed under VS have 2 places to work with:
  • Design View
  • Code View

  • Adding new Forms in the project

    A project can contain any no. of forms in it, to add a new form under our project i.e. 'WindowsProject', open Solution Explorer -> right click on project and select Add -> "Windows Form", which adds a new form Form2.cs. To run the new form, go to Program class and change the code under Application.Run method as Form2.