Datasheet

Part I: Getting Started
12
The code associated with clicking the source code icon shown in Figure 1 - 8 is shown in Figure 1 - 9 .
When you click the source code icon, notice that another tab is added at the top of the Source window.
One tab has form1.cs (Design) on it, while the other tab has form1.cs. The first tab is for the view of the
form in the design mode. (The design mode is shown in Figure 1 - 7 .) The second tab is the source code
mode and shows you the code for the program under development. Even though you haven t written
any code yourself, Visual Studio has already written some for you behind your back! You can see the
TestProgram C# source code in Figure 1 - 9 .
Figure 1 - 9
It s not necessary that you understand the code shown in Figure 1 - 9 at this time. All you re trying to do
at this point is write a very short program to see if the installation was done correctly. However, you will
be spending a lot of time in the source code window as you write your own programs.
Adding an Object to a Windows Form
A form with nothing on it isn t terribly interesting. Let s change the form so that, when the program
runs, it displays the message, My first program. You need to add a label to the form object shown in
the Source window in Figure 1 - 7 to hold your program message. There are two ways to add a label
object to a form. First, as shown in Figure 1 - 10 , you can click the label object in the Toolbox and, while
holding the left mouse button down, drag the label over to the form and release the mouse button.
Second, you can simply double - click the label object in the Toolbox. The mouse double - click causes
Visual Studio to place a label object near the upper left - hand corner of the form shown in the Source
window.
You can click the label in the Source window while holding the left mouse button down and drag the
label to wherever you want it to appear on the form object. When you have positioned the label object
where you want it on the form, simply release the mouse button.
ISBN: 978-0-470-26129-3 I Title: Beginning C# 3.0 : An Introduction to Object Oriented Programming I SKU: 9785CH0009874