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:
The rules for naming controls are illustrated here
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
C# code, a file that contains program code is called a source code file, is organized in three ways:
Each time a new project is created the following two source code files are automatically created
Organization of Form1.cs:
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 = ""
Programmers frequently use blank lines and indentation in their codes to make the code more human-readable.
A line comment appears on one line in a program such as: // This is an example of a comment line
Or a block comment can occupy multiple consecutive lines in a program like:
/*
Line one
Line two
*/
Visual Studio code editor examines each statement as you type it and reports any syntax errors that are found.
If a syntax error is found, it is underlined with a jagged line as it is illustrated as under: