Windows Forms Development

The Form class in the System.Windows.Forms namespace represents a standard window that contains Windows controls. In this section, we walk you through the development of a Windows Forms application and introduce you to the rich set of Windows controls that can be used on a Windows Form.

Windows Forms Application

All Windows Forms applications start out with a derived class from the System.Windows.Forms.Form class. A simple Windows Forms application looks like the following:

public class MyForm : System.Windows.Forms.Form
{
  public MyForm(  )
  {
    Text = "Hello World";
  }
  public static void Main(  )
  {
    System.Windows.Forms.Application.Run(new MyForm(  ));
  }
}

Basically, you define a class MyForm, which derives from the System.Windows.Forms.Form class. In the constructor of MyForm class, you set the Text property of the Form to Hello World. That’s all there is to it. The static Main function is the entry point to all applications. In the entry-point function, you call the static method Application.Run, which starts the message loop for the application. Because you also pass a form-derived object MyForm to the Run method, what we have is a Windows Forms application.

You can also include references to the namespaces to avoid typing the fully qualified name of classes such as System.Windows.Forms.Form or System.Windows.Forms.Application. To do this, include the following line at the beginning of the source file, and omit the System.Windows.Forms prefix to your class names: ...

Get .Net Framework Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.