Introductory Lab
A first C# windows application
1 START / programming -> Visual Studio
Create a new project
In Location: - browse to where you want to store your C# projects
In Name: - choose some name e.g. HelloWindowsWorld
Make sure “Close Solution” is checked
1
2
.2 Should display Form1 in design mode
Right click on the form and select “View Code” to see the code for the class.
3
The code should look something like:
using System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace HelloWindowsWorld
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}
It is a “partial class” because a lot of the code generated for class Form1 is hidden
from you in another file called [Link]. You can access this file from
Solution Explorer panel on the right. You may need to expand the [Link] node in
order to see it.
4
You shouldn’t normally need to edit the code in [Link].
In the Solution Explorer you can also see that another class file has been generated
called [Link]. If you look at the code for this you can see that it is the program
that creates and instance of Form1and runs it.
2.3 Select the [Link] design view (DoubleClick on the form).
If the Toolbox is not already on display select View->Toolbox. You can “pin” the
toolbox so it shows all the time
5
Click on “All Windows Forms” in the toolbox to display some standard GUI widgets.
Add a label and a button to the form by dragging them
6
7
8
Check if the Properties panel is not showing, Go to View->Properties Window
Use the Properties panel to change the text of the button to “click me”
9
Change the name of the label to lblHello
10
Select the button on the form.. Double click on it. This should show the code:
Inside the { } add in some code to display hello world in the label e.g.
[Link] = "hello world"; // This is an assigment
11
Build and run the program by clicking on the Start button at the top ( with a green
arrow )
12