How to start a new project
From the main menu click on New Project and then give a name to your project, for example the default, WpfApp1, and then click
Ok or press Enter.
The following screen opens up to start the newly created application.
A Visual C# application project starts with creating its GUI with Designer, Toolbox, and Property window. In the Designer, an empty form is automatically created where:
- An application's GUI is made of forms and controls
- Each form and control in the application's GUI must have a name as ID. The default blank form is named ";Form1" automatically
- The appearance and other characteristics of a GUI object are determined by the object's properties
The rules for naming controls are illustrated here
Introduction to C# programming
GUI applications are event-driven which means they interact with users. An event is a user's action including mouse clicking and key pressing.
Double clicking a control, such as Button, will link the control to a default Event Handler
- An event handler is a method that executes when a specific event takes place
- A code segment similar to the following will be created automatically: private void myButton_Click(object sender, EventArgs e) {}
C# code, a file that contains program code is called a source code file, is organized in three ways:
- Class: a container that holds methods
- Namespace: a container that holds classes
- Method: a group of one or more programming statements that perform some operations
Each time a new project is created the following two source code files are automatically created
- Program.cs file: contains the application’s start-up code to be executed when the application runs. In Visual Studio 2017, the file is called App.xaml.cs file:
- Form1.cs contains code that is associated with the Form1 form. In Visual Stusio 2017, it's called MainWindow.xaml.cs
Organization of Form1.cs:
- The using directives indicate which namespaces of .NET Framework this will use.
- The user-defined namespace of the project not .NET Framework namespaces

- Class declaration and a method
Basically, C# code is organized as methods, which are contained inside classes, which are contained inside namespaces
By adding the following bold line to a Button's event handler, a Label control can display output of the application.
private void showAnswerButton_Click(object sender, EventArgs e)
{
answerLabel.Text = "Abraham Lincoln";
}
The Text property accepts string only and to clear the text of a Label, the following code can be used: answerLabel.Text = ""