You are on page 1of 38

2

Introduction to the
Visual Studio.NET IDE

Objectives
• To become familiar with the Visual Studio.NET
Integrated Development Environment.
• To be able to understand the types of commands
contained in the menus and the tool bar.
• To identify and understand the use of the important
windows in Visual Studio.NET.
• To be able to create and customize forms and
components.
• To understand Visual Studio.NET’s help sections.
• To be able to create, compile and execute a simple
program.
Seeing is believing.
Proverb
Form ever follows function.
Louis Henri Sullivan
Intelligence… is the faculty of making artificial objects,
especially tools to make tools.
Henri-Louis Bergson
Our life is frittered away by detail… Simplify, simplify.
Henry Thoreau

© Copyright 1992–2002 by Deitel & Associates, Inc. All Rights Reserved. 6/29/01

103 Introduction to the Visual Studio.NET IDE Chapter 2

Outline
2.1 Introduction
2.2 Integrated Development Environment (IDE) Overview
2.3 IDE Features
2.4 Start Page
2.5 Menu Bar
2.6 Visual Studio.NET Windows
2.6.1 Solution Explorer
2.6.2 Properties Window
2.6.3 Class View Window
2.6.4 Object Browser Window
2.6.5 Server Explorer
2.7 Toolbox
2.8 Writing Code
2.9 Compiling
2.10 Running Programs
2.11 Using Help
2.12 A Simple Program: Displaying Text

2.1 Introduction
Visual Studio.NET is Microsoft’s new integrated development environment (IDE), cur-
rently in its Beta 2 version. It is a single program that allows users to create, document, run,
and debug programs written any of the .NET languages. Visual Studio.NET also offers
tools for editing HTML, XML, and data. Visual Studio.Net’s flexibility makes it a powerful
tool—projects with components from different languages can be created using one pro-
gram. In this chapter we shall overview Visual Studio.NET’s features and create a simple
program.

2.2 Integrated Development Environment (IDE) Overview
We will use Visual Studio.NET to develop console applications and Windows applications.
Console applications are text-based and run from the command prompt (Fig. 2.1). Win-
dows applications have a graphical user interface (GUI) contained in a form (Fig. 2.2). A
GUI is the visual portion of the program (i.e., buttons, etc.)–this is where the user enters
data (called inputs) to the program and where the program displays its results (called out-
puts) for the user to read. Forms contain controls, which are graphical components (such as
buttons and textboxes) that allow the user to interact with the program.

© Copyright 1992–2002 by Deitel & Associates, Inc. All Rights Reserved. 6/29/01

Chapter 2 Introduction to the Visual Studio.NET IDE 104

Every window in Visual Studio.NET can be closed by clicking the left mouse button
once on the black “x” in the upper right corner. We refer to single-clicking with the left
mouse button as selecting or clicking, and we refer to double-clicking with the left mouse
button simply as double-clicking. Some windows have special features which will be dis-
cussed in the upcoming sections.

Console applications are text based.

Fig. 2.1 Sample console application (Need Permission).

Sample inputs
and outputs

Fig. 2.2 Sample Windows application (Need Permission).

Programs in Visual Studio.NET are organized into projects and solutions. A project is
a group of related files. These files are compiled together to create a running program. A
solution is a group of projects used to solve a user’s problem. Each project in the solution
may perform a different task. In this chapter we will create a single-project solution. New

© Copyright 1992–2002 by Deitel & Associates, Inc. All Rights Reserved. 6/29/01

These include auto-hiding windows. Inc. Edit.105 Introduction to the Visual Studio. Expand a window by moving the mouse over the window name or icon on the © Copyright 1992–2002 by Deitel & Associates. The top of the IDE window (the title bar) displays the name of the project (SampleApplication). and customizable toolbars. 6/29/01 .. All Rights Reserved. etc.3 IDE Features Visual Studio. To save screen space. each of which we overview shortly.NET environment.NET environment. The IDE consists of various windows. Design mode will be discussed later in the chapter. windows can be set to auto-hide when the mouse moves away from them. Title Bar Menu Form Fig. 2. The menu bar con- tains several menus (File.NET has many helpful features. The tool bar contains several icons that provide quick access to commonly used features. win- dow tabbing. a menu bar and a tool bar.). (Need Permission) 2.cs). Figure 2. We discuss several of these tool bar icons in this chapter and others later in the book.3 Visual Studio. the mode of the IDE (design mode) and the file being viewed (Form1.3 shows a sample Visual Studio. View. the pro- gramming language (Microsoft Visual C#).>Visual C# Projects and selecting either a console or Windows application..NET IDE Chapter 2 projects can be created by choosing File>New>Project.

Figure 2. Moving the mouse pointer over a toolbar icon highlights it and displays a descrip- © Copyright 1992–2002 by Deitel & Associates.5 Demonstrating window tabbing. click the pin icon in the upper right corner (as in Fig.5.4).4 Demonstrating the auto-hide feature (Need Permission). select Window>Auto Hide All. (Need Permission) The IDE contains many toolbars which provide shortcuts to commonly used com- mands. If multiple document win- dows are open. To quickly hide all windows. 2. Tab for hidden window Frontmost tab Fig. Toggle Auto-expand Close Window Mouse over window name Fig. Clicking a tab will bring the selected document up front. 6/29/01 . 2. The user can “pin” down a window to keep it open after it has expanded. each will have its name on a tab as in Fig. All Rights Reserved. Inc. To do this.NET IDE 106 side of the screen. Window tabbing allows fast access to many documents. This holds the window in place until it is closed or unpinned.Chapter 2 Introduction to the Visual Studio.4 shows an example of this: when the mouse is over the window it expands and when the mouse leaves it recedes. 2. 2.

6 Changing toolbar icons.6). (Need Permission) When the mouse pointer lies over an icon a tool tip appears (Fig. Click the name of a section to browse it. Clicking the down arrow displays a drop down list. the Start Page appears (Fig. from which a new tool can be chosen. 2. All Rights Reserved.7 Tool tip demonstration (Need Permission).8). 2. Inc. 2. online newsgroups. A down arrow associated with a tool indicates that other tools that can be selected instead of the current one (Fig. 2. downloads.NET IDE Chapter 2 tion. This HTML docu- ment contains helpful links. and user profile settings.107 Introduction to the Visual Studio. such as recent projects. Tool tips can appear for other components as well.7). Icon Select Toolbar Icon Fig.4 Start Page When loading C# for the first time. A down arrow that is not associated with an icon allows the user to edit the toolbar itself by adding or removing tools. Tool tips provide information about what each icon means. 2. All features except Get © Copyright 1992–2002 by Deitel & Associates. 2. 6/29/01 . Tool tip text Fig. This is described later in the chapter.

8 Visual Studio. the last loaded solution. Figure 2. Option At Startup selects how Visual Studio.NET begins—with the Start Page. 6/29/01 . All Rights Reserved. though the default settings are adequate.Chapter 2 Introduction to the Visual Studio. The “C# developer” profile filters help for topics related to C#. Inc. The user can select settings for the Window Layout and Keyboard Scheme. (Need Permission) The Get Started section contains links to recent files. © Copyright 1992–2002 by Deitel & Associates. To access the Start Page if it is closed.NET IDE 108 Started and My Profile require an Internet connection.NET is loaded. select Help>Show Start Page. rather than the entire help file. which uses Microsoft’s Internet Explorer. Internet Explorer navigation buttons Location bar Sections Recent Projects Fig. or an empty environment.NET.8 displays the Web browsing features of the IDE. this will be empty. a New dialog box. which lists projects name and modification dates. Figure 2. If this is the first time Visual Studio.NET to search only certain parts of help (such as articles relating to C#). The IDE must be restarted for any internal/external changes to take effect. an Open dialog box. Clicking on the project name will open it.NET’s Start Page.8 also displays a sample Get Started section. Show Help selects whether help appears internally (inside the IDE) or externally (in a separate window). The My Profile page allows the user to customize the layout of Visual Studio. The Help Filter list causes Visual Studio. 2.

etc. Fig.6 Visual Studio. undo. Edit Contains options such as cut. Windows Contains options for arranging and displaying windows. find. etc. printing projects. © Copyright 1992–2002 by Deitel & Associates.10. Debug Contains options for debugging and running a program.NET menu bars (regular and design mode) (Need Permission). paste. 2. Tools Contains options for IDE tools. 2.NET IDE Chapter 2 2. Help Contains options for getting help. not editing code (indicated by [design] after the file name). Data Contains options for using databases. and options for customizing the environ- ment. They allow the user to explore files. 2.11) or in View>Other Windows. 2.9 are summarized in Fig. Project Contains options for adding features such as forms to the project. All Rights Reserved. 2. and view class details. Normal menu Design menu Fig. Note that some menus only appear when designing a form. Menus contain groups of related capabilities from which the user may select appropriate choices. They can be accessed using the toolbar below the main menu (Fig. Build Contains options for compiling the program. 2. add-ins. closing projects. 6/29/01 .NET menu summary. delete.5 Menu Bar Commands for developing. Menu Description File Contains options for opening projects. The menus of Fig.NET Windows The following windows are important to the Visual Studio. examine and change the properties of components.9 Visual Studio.10 Visual Studio. Figure 2. Inc. Format Contains options for arranging components in a form [design mode only].NET IDE.109 Introduction to the Visual Studio.9 shows the menus displayed on the menu bar. View Contains options for displaying IDE windows and tool bars. maintaining and executing programs are contained in the menus.

The startup project can be changed. and the right- most displays the Properties Window for the selected file. each control type has its own set of properties. This plus/minus convention will be used in many other parts of Visual Studio. Properties such as Width and Height are common to both forms and con- © Copyright 1992–2002 by Deitel & Associates. the toolbar also displays icons for viewing the code or design.6.2 Properties Window The Properties window (Fig.12) allows the user to browse any of the files in a solution. 2.13) displays the properties for a form or control. 2.NET IDE 110 Solution Explorer Properties Toolbox Object Browser Fig. Bold text indicates the startup project of the solution. 2. The leftmost refreshes.NET.11 Visual Studio. All Rights Reserved. if appropriate. A plus sign means the tree can be expanded and a minus means the tree is already expanded. and a project is a group of related files.1 Solution Explorer The Solution Explorer window (Fig. 2. The user can also expand or collapse a tree by double clicking the name. Proper- ties are attributes such as size. 6/29/01 . or the project that runs when the program is executed. The plus and minus boxes to the left of the project and solution names expand or col- lapse the tree (similar to Windows Explorer). Refresh Display all files Properties Collapse tree Expand tree Fig. The Solution Explorer has a toolbar at the top with three icons.12 Solution Explorer window (Need Permission). 2.NET toolbar for important windows (Need Permission). Like a form. etc. Remember that a solution is composed of projects.Chapter 2 Introduction to the Visual Studio.6. position. but for single-project solutions the startup project is the only project. If browsing a particular file. Inc. 2. the middle displays all files (including previously hidden ones).

Categorized Icon Alphabetic Icon Property Current value Description Fig. such as Appearance. All Rights Reserved. The upper toolbar sorts the properties either alphabetically (by clicking the Alpha- betic icon) or categorically (by clicking the Categorized icon). while other properties are unique to a form or control.6. (Need Permission) 2.3 Class View Window As mentioned in Chapter 1.111 Introduction to the Visual Studio. The upper left icon can group or sort the classes. Clicking the Categorized icon lists properties by categories. The upper right icon creates a new folder. Misc. Alphabetic lists the properties in alphabetical order and is the default. Inc. Controls often differ in the number and type of properties.14) can browse user-de- fined classes and display their contents. classes are a natural way to organize data and methods and will be discussed later in the book.13 Properties window. © Copyright 1992–2002 by Deitel & Associates. etc. 2. The bottom of the Properties window explains the prop- erty being examined. 2. 6/29/01 . depending on the tool selected. The Class View window (Fig. Behavior. Layout. The scrollbar can be used to scroll through the list of properties (by dragging the scrollbar up or down). We discuss setting individual properties later in this chapter and throughout the book.NET IDE Chapter 2 trols. helping to orga- nize classes.

14 Class View window. 2. 6/29/01 .6. We will learn how to create the summary information later in the chapter.Chapter 2 Introduction to the Visual Studio.NET IDE 112 Project name Class name Class members Fig. It can display the details of any installed component. All Rights Reserved. The bottom pane contains a summary and other information about the member being examined. (Need permission) 2. © Copyright 1992–2002 by Deitel & Associates.4 Object Browser Window The Object Browser window is similar to Class View but much more powerful. and the right pane contains its members (data and meth- ods). The left pane contains a tree of objects. Inc. rather than only user-defined classes. This displays a class’s documentation and allows the user to quickly research other classes.

All Rights Reserved. © Copyright 1992–2002 by Deitel & Associates. performance counters and Web Services. By navigating the tree.6. SQL servers.113 Introduction to the Visual Studio. Inc.15 Object Browser window (Need Permission). 6/29/01 . We will use these features in upcoming chapters. databases.NET IDE Chapter 2 Current object Current property Description Fig. The Server Explorer can also monitor applications distributed among multiple computers. 2. it is possible to examine components such as event logs. 2.5 Server Explorer The Server Explorer allows the user to import components from other servers by drag- ging and dropping them onto the form.

Controls are prepack- aged components that can be reused. such as buttons and textboxes. 2. The user can scroll through the individual items by using the black arrows on the right.NET IDE 114 Computer name Available components Fig. In this chapter. Notice that no tool tips are displayed because the components are already labeled. © Copyright 1992–2002 by Deitel & Associates. 2. All Rights Reserved.16 Server Explorer window (Need Permission). The toolbox contains groups of related components (Data. Compo- nents. Inc. 2. etc. This allows program- mers to quickly create applications without having to implement every component—they are already created. we overview the toolbox controls and in later chapters we discuss these con- trols in greater detail. 6/29/01 .17) contains controls used to customize forms.).Chapter 2 Introduction to the Visual Studio. Windows Forms.7 Toolbox The toolbox (Fig. The contents of a group can be expanded by clicking the group name.

including code collapsing. Although we have not yet discussed C# syntax. Putting the mouse over either symbol displays its con- © Copyright 1992–2002 by Deitel & Associates. A plus indicates the code can be expanded.NET IDE Chapter 2 Component group Scroll arrow Component Fig. These blocks can be expanded or collapsed by clicking the plus or minus arrows on the left. 2. 2. To view the code in a Win- dows application.18. 2.NET has many features to aid in writing code. The collapsed code is replaced by an ellipsis (. This displays the code cor- responding to the form. and Intellisense (discussed later this section).. All Rights Reserved. we can still overview the features of writing code. 6/29/01 .115 Introduction to the Visual Studio.8 Writing Code Visual Studio. To bring up the code window. as in Fig. Collapsed comments are replaced by (/**/).. such as methods. right click the form and select View Code.17 Toolbox window (Need Permission).). use the Solution Explorer to open the C# file. and com- ments. Inc. Code collapsing groups related blocks of code. classes. syntax highlighting. and a minus means the code is already expanded.

known as the dot operator. This feature organizes code and allows the programmer to concentrate on selected groups of code (rather than having to view the entire program at once). with a red wavy line.” symbol lists its data members and methods.icon) Syntax highlighting Syntax error Fig. Syntax highlighting colors the code depending on its meaning. Inc. rather than remember. This allows quickly identifies the meaning of a piece of text. 6/29/01 .Chapter 2 Introduction to the Visual Studio. Intellisense is a helpful tool used to display the data members and methods of an object. Later in the book we will discuss how this period. Collapsed code (+ icon) Ellipsis replaces collapsed code /**/ replaces collapsed comments Collapsed code contents Expanded code (.NET underlines syntax errors. In addition.NET IDE 116 tents as a tool tip. program comments in green. These fea- tures allow the programmer to avoid syntax errors entirely. C# keywords (reserved words) are colored in blue. All Rights Reserved. © Copyright 1992–2002 by Deitel & Associates. Intellisense also lists the method parameters when writing method calls. what is needed. XML tags in grey. is used in object-oriented programming. The user can now select. Following an object’s name by the “. Visual Studio.18 Code features in Visual Studio. and other text in black.NET (Need Permission). such as unmatching parentheses. rather than finding and fixing them at compile time. 2.

2.117 Introduction to the Visual Studio.19 Intellisense demonstration (Need Permission).20). a previously compiled version will run (if it exists).NET IDE Chapter 2 Current object List of contents Fig. If there were errors. This is discussed in detail in Appendix E.NET also allows easy code documentation. it must be compiled (or built). 2. execution will stop and the user can fix the compilation errors. Visual Studio. grey XML tags may appear (as in Fig. 2.NET will ask if it should continue.18). The Output window will pop up and display the status of the compilation. Inc. The details of debugging a program are in Appendix F. Inside code comments. To do this. Writing descriptions between these tags allows the user to generate XML documentation pages and describe classes for the Object Browser. If it does continue. Visual Studio. 2. Otherwise.20). The specifics of the errors will appear in the Task List at the bottom of the screen (Fig. 2.9 Compiling After writing code. © Copyright 1992–2002 by Deitel & Associates. select Build>Build. including any errors (as in Fig. 6/29/01 . which will be most useful after learning more about C#. All Rights Reserved.

Double-clicking an error will move the cursor to the appropriate line. Once the compilation has no errors the program can be executed.NET IDE 118 Task List Errors Output window Fig. either select Debug>Start Without Debugging or add a line in the program to wait before exiting (we will learn how to do this in the upcoming chapters). All Rights Reserved. Click the blue Start arrow in the up- per toolbar or select Debug>Start. Depending on the type of program. the Output window will display status information and the console will display output from the program.20 Compilation errors and the Task List (Need Permission). 2. The Task List contains the cause of the error. the file it is in. 6/29/01 . As programs get more complicated. Some console programs may require command line arguments. running without debugging is not recommended— waiting before exiting is the preferred choice. 2. either a console or a Graphical User Interface (GUI) will pop up on the screen. the program can be run. Inc. and from there the user can fix the problem. Command line argu- ments are strings of text.Chapter 2 Introduction to the Visual Studio. © Copyright 1992–2002 by Deitel & Associates. To prevent this. used to pass information to console applications when they begin. For console programs. When the program finishes the console will close.10 Running Programs After successfully compiling. and its line number.

2. The user can interact with this program just like any other. Command line arguments Fig. All Rights Reserved. 2. Text output and status information appears in the Output window.e. In each case.21). The Dynamic Help window can be accessed through Help>Dynamic Help if it is not on the sidebar. Regular help. a new window will appear containing the specified form.NET. “Getting Started” information as well as a toolbar for the regular help features. 2. 6/29/01 . available through the Help menu.NET IDE Chapter 2 To set them in Visual Studio. the text by the cursor).119 Introduction to the Visual Studio. Go to Configuration Properties>Debug- ging>Start Options>Command Line Arguments and enter the proper arguments (Fig. as in Fig.21 Setting command line arguments. Run the program as described above. maximizing. (Need Permission) For Windows programs. and resizing. samples. © Copyright 1992–2002 by Deitel & Associates. a filter can be used to narrow the search to articles relating to C# only. right click the project’s name in the Solution Explorer and select Properties. an alphabetical index.22. allows the user to browse a categorized table of contents.11 Using Help Visual Studio.NET has an extensive help section. Inc. or perform a search. including minimizing. It lists relevant help entries. 2. Dynamic help provides a list of helpful articles based on the current context (i.

The program consists of one form and uses one Label control to display © Copyright 1992–2002 by Deitel & Associates. A relevant article will immediately pop up in a separate window (external help) or in a tabbed window (internal help). All Rights Reserved. select a word using the cursor and press F1. Inc. 6/29/01 .23).22 Dynamic Help window (Need Permission). Context-sensitive help is similar to Dynamic Help except it immediately brings up a relevant help article rather than presenting a list.Chapter 2 Introduction to the Visual Studio.12 A Simple Program: Displaying Text In this section we will create a program that displays the text “Welcome to C#!” and an image (Fig. 2. 2. To use context-sensitive help. 2.NET IDE 120 Cursor position Relevant help articles Fig. Dynamic Help and context-sensitive help can also be used with the graphical com- ponents in forms. Click the component and then browse the Dynamic Help window or press F1 to display context-sensitive help.

© Copyright 1992–2002 by Deitel & Associates. Open up Visual Studio. Visual C# programming involves a com- bination of writing a portion of the program code and having Visual Studio.23 A simple program at run time (Need Permission). The program is a Windows application because it has a GUI.23 shows the program at runtime.121 Introduction to the Visual Studio. 2.NET IDE Chapter 2 the text and one PictureBox to control the image.NET with sufficient information so that it can automatically generate all or a major portion of the pro- gram code for our program.NET generate the remaining code. Inc. 6/29/01 .24). Fig. dragging and dropping) we provide Visual Studio. Name the project and select OK. Instead. we begin our discussion of writing program code. 2. All Rights Reserved. 2. Create the new project. Throughout the book we will produce increasingly substantial and powerful programs.NET and select File>New>New Project. In the next chapter.>Vi- sual C# Projects>Windows Application (Fig. Here are the steps to create.. We do not write a single line of program code. A blank form labeled Form1 appears. We are creating a GUI so we need a new Windows appli- cation. run and terminate this first program: 1.. we introduce the techniques of visual programming in which through various programmer gestures (such as using the mouse for pointing. Fig. clicking.

Select the form.Chapter 2 Introduction to the Visual Studio. To change the value of this property. The form’s Text property determines what appears in the form’s title bar.25 Setting the Label’s Text property (Need Permission). All Rights Reserved. set the Text property to A Simple Program (as in Fig.NET IDE 122 Fig. Inc. click in the field next to Text (this field displays Form1). Sizing handles that are white are enabled and can be used for resizing. 3. In the Properties window. If the Properties window is not displayed click the icon in the toolbar. Sizing handles are not visible during program execution. 6/29/01 . Resizing the form. The grid dots on the © Copyright 1992–2002 by Deitel & Associates. 2. Delete the existing value using the Backspace key or Delete key and enter the new value. This updates the form’s title bar in the design area. In the beta version of Visual Studio. 2. 2.26). Hit the Enter key (Return key). Click and drag one of the form’s enabled sizing handles (the small squares around the form shown in Fig. Note the change in the mouse pointer when it is placed over a sizing handle. Setting the form’s title bar.25). Selected Name and type property of object Property description Property value Fig.NET. 2. gray sizing handles are enabled and the programmer cannot use them to resize the form. 2.24 Creating a new Windows application (Need Permission).

Inc. Select the box rep- resenting yellow. © Copyright 1992–2002 by Deitel & Associates. Title bar Grid Inactive sizing handle New mouse cursor Active sizing handle Fig. Clicking BackColor in the Properties window causes a down-arrow button to appear next to the property value as shown in Fig. When clicked.123 Introduction to the Visual Studio. Changing the form’s background color.NET IDE Chapter 2 background of the form are used for aligning controls and are only visible at de- sign time. The form’s background color becomes the default background color of components added to the form. 2. 6/29/01 .26 Form with sizing handles (Need Permission). The BackColor property specifies a form or control’s background color. 4. Note that BackColor displays a small rectangle representing the cur- rent color. All Rights Reserved.27. the down arrow displays a window with the tabs Sys- tem (the default) Web and Custom. The palette disappears and the form’s background color changes to yellow. Click the Custom tab to display the palette (a group of colors from which the user selects one by clicking). 2.

Setting the Label’s display. 2. 6. The form and Label each have their own Text property—with each being completely independent of the other. Adding a Label control to the form. When the sizing handles appear around the Label. the Properties window displays the Label’s properties. The Label’s Text property determines what text (if any) the Label displays.28 Adding a new Label to the form (Need Permission). Double-click the Label control in the tool- box to create a Label with sizing handles in the upper left corner of the form (Fig. Inc. Forms and con- © Copyright 1992–2002 by Deitel & Associates. The Label displays the word Label1 by default. Clicking the form causes its properties to be displayed in the Properties window.Chapter 2 Introduction to the Visual Studio.28).27 Changing property BackColor (Need Permission). 5. 2. 6/29/01 . All Rights Reserved. 2. Double clicking any toolbox control results in a control being created and placed in the corner of the form.NET IDE 124 Current color Down arrow Custom pallete Fig. New background color Newly inserted Label Fig.

Serif. select the Tex- tAlign property—which determines how the text is aligned within the Label boundaries. Inc. the Font window of Fig. Select the center grid item. Under the Size category select 24 and press OK.125 Introduction to the Visual Studio. Bold. 2.) can be selected.29 Label in position with its Text property set (Need Permission). 2. If the label is not big enough to hold all of the text. use the sizing handles to resize it. Clicking the Font property value causes an ellipsis button to appear (Fig. 2. Label centered with updated Text property Fig. When this button is pressed. Next.32).) and font size (8. Resize the label using the sizing handles. 10.29). Drag the Label to the top center of the form or move it using the arrow keys. A three-by-three grid of alignment choices will appear. 2. etc. 2.31 appears. Setting the Label’s font size and aligning the Label’s text. © Copyright 1992–2002 by Deitel & Associates. All Rights Reserved. similar to the ellipsis used in code collapsing. etc. etc. At this point. Set the Text prop- erty of the Label to Welcome to C#! (Fig.NET IDE Chapter 2 trols can have properties with the same name without conflict. 7. The ellipsis indi- cates the selection will be expanded. font style (Regular. The font name (MS Sans Serif.). the Label may be too small for the font size. corresponding to where the text will appear in the Label (Fig. 6/29/01 .30). The current font is applied to the text in the Sample ar- ea.

© Copyright 1992–2002 by Deitel & Associates.30 Properties window displaying the Label’s properties (Need Permission). 6/29/01 . Current font Font sample Fig.31 Font window for selecting fonts. Inc. 2.NET IDE 126 Ellipsis indicates expansion Fig. styles and sizes (Need Permission). 2. All Rights Reserved.Chapter 2 Introduction to the Visual Studio.

Find the PictureBox in the toolbar and double click it to add it to the form. To center the image.127 Introduction to the Visual Studio. This step is similar to step 5. All Rights Reserved. and the Image attribute will show a small preview. If both the Label and PictureBox are selected. This component allows the user to display an image on the form.33 Inserting and aligning the PictureBox (Need Permission). either by dragging or using the arrow keys (Fig. Browse for a picture to insert (of the proper format.NET IDE Chapter 2 Text alignment options Center alignment Fig. 9. which opens an Open dialog. Adding a PictureBox to the form. 6/29/01 . 2. Updated Label New PictureBox Fig. Click the ellipsis button. adding the Label.33). 8.32 Centering the text in the Label (Need Permission). change the SizeMode attribute to Center- © Copyright 1992–2002 by Deitel & Associates. such as GIF or JPEG) and press Enter. Open the PictureBox’s Properties window and find the Image attribute. The PictureBox will display the image. they can be aligned using For- mat>Align>Centers. 2. 2. Inc. Move it un- derneath the Label. Insert an image.

e. tool bars. 2. The project file contains the names and locations of all of the files in the project. 2. While in run mode the program is executing and the user can only inter- act with a few IDE features. The C# file contains the source code for the program that was just created. The user can save the entire project or just the C# file we created separately.e. While in design mode. Prior to this step. Note that the IDE title bar displays [Run] and that most tool bar icons are disabled.35 shows the IDE in run mode. menus. click the Start button or select Start from the Debug menu. etc. depending on what is highlighted in the Solution Explorer. Save the project. the program is not executing).. All Rights Reserved. Run the project. 6/29/01 .Chapter 2 Introduction to the Visual Studio. the programmer has ac- cess to all the environment windows (i. we have been working in the IDE design mode (i. © Copyright 1992–2002 by Deitel & Associates. toolbox and Properties). Do not lose all this hard work! Click the Save All icon or select File>Save All. If the PictureBox or form is too small. To execute or run the program. Features that are not available are disabled and grayed out.34). 11. resize each until the image fits (Fig.NET IDE 128 Image. Newly inserted image Fig.. Figure 2. By choosing Save All both the project and the C# file are saved. 10. Inc.34 Inserting an image into the PictureBox (Need Permission).

• Console applications are text-based and run from the command prompt. a single program that al- lows users to create. with the running application in the foreground (Need Permission).. © Copyright 1992–2002 by Deitel & Associates. where the user enters data to the program and where the program displays its results for the user to read. Terminating execution. All Rights Reserved. run.35) or the End button (in the toolbar) terminates program execution and places the IDE in design mode.NET languages.129 Introduction to the Visual Studio.e.NET is an IDE (Integrated Development Environment). the “x” at the top right corner of Fig. 12.35 The IDE in run mode. Windows applications have a graphical user interface (GUI) and are displayed on a form. 2. • A GUI is the visual portion of the program. Inc. 2.NET IDE Chapter 2 Run mode Design (note grid) Running application Fig. document. and debug programs written any of the . 6/29/01 . SUMMARY • Visual Studio. Clicking form’s Close button icon (i.

and comments. etc. position. Properties are attributes such as size. downloads and user profile settings.NET. Inside code comments.. Writing descriptions between these tags allows the user to generate HTML documen- tation pages as well as describe classes for the Object Browser. A solution is a group of projects compiled together to solve a user’s problem. • The Server Explorer can import components from other servers. • The Object Browser window is similar to Class View but much more powerful. reusable components. • The My Profile page allows the user to customize the layout of Visual Studio. • Window tabbing allows fast access to many documents. • Windows can be set to auto-hide when the mouse moves away from them. XML tags in grey. • Syntax errors are underlined with a red wavy line. • Code collapsing groups related blocks of code. All Rights Reserved. such as methods. Intellisense also lists the method parameters in a method call. not editing code. • The Solution Explorer window can browse any of the files in the solution.NET also allows easy code documentation. rather than the entire help file. and col- lapsed comments are replaced by (/**/). The properties can be sorted either alphabetically or categorically. Tool tips can appear for other compo- nents as well. • Tool tips provide information about what each icon means. • Menus contain groups of related capabilities from which the user may select appropriate choices. the mode of the IDE and the file being viewed. Collapsed code is replaced by an ellipsis (. Pin down a window to keep it open after it has expanded. © Copyright 1992–2002 by Deitel & Associates. • Syntax highlighting colors the code depending on its meaning.). • Intellisense displays the data members and methods of an object. and other text in black. grey XML tags may appear. A plus sign means the tree can be expanded and a minus means the tree is already expanded. It also contains a summary and other infor- mation about the member being examined. • The Class View window can browse user-defined classes and display their contents. • The Start Page appears when loading C# for the first time and contains recent projects. • The title bar displays the name of the project.NET IDE 130 • Programs in Visual Studio. • The Properties window displays the properties for a form or control. • Visual Studio.NET are organized into projects and solutions. Bold text indicates the startup project of the solution. classes. online newsgroups. • The toolbar contains several icons that provide quick access to commonly used features. • The toolbox contains controls used to customize forms. It allows the user to browse the details of any installed component.Chapter 2 Introduction to the Visual Studio. Inc. These blocks can be expanded or collapsed.. the programming language. This plus/minus convention will be used in many parts of Visual Studio. Some menus only appear when designing a form. A down arrow associated with a tool indicates that other tools that can be selected instead. • The IDE contains many toolbars which provide shortcuts to commonly used commands. 6/29/01 . or the project that runs when the program is executed.NET. • Plus and minus boxes can expand or collapse a tree. • Controls are prepackaged. • The Help Filter list allows the user to search only certain parts of help (such as articles relating to C#). A project is a group of related files. C# keywords (reserved words) are colored in blue. program comments in green.

A blank form labeled Form1 will appear. • To set command line arguments. Sizing handles are not visible during program execution. gray sizing handles are enabled and the programmer cannot use them to resize the form. In the beta version of Visual Studio. • Visual C# programming involves a combination of writing a portion of the program code and hav- ing Visual Studio. • The form’s Text property determines what appears in the form’s title bar. a program can be run. 6/29/01 . an al- phabetical index. The Task List contains the cause of the error. Text output and status information appears in the Output window. Go to Configuration Properties>Debugging>Start Options>Com- mand Line Arguments and enter the proper arguments. • For console programs. The form’s back- ground color becomes the default background color of components added to the form. When this button is pressed. the Output window will display status information and the console will display output from the program. • For Windows programs. • Clicking the Font property value causes an ellipsis button to appear. To use context-sensitive help. Sizing handles that are white are enabled and can be used for resizing. available through the Help menu. • The BackColor property specifies a form or control’s background color. select a word using the cursor and press F1. This updates the form’s title bar in the design area. To prevent this. can browse a categorized table of contents. Hit the Enter key (Return key). • The grid dots on the background of the form are used for aligning controls and are only visible at design time. and its line number. Delete the existing value using the Backspace key or Delete key and enter the new value.. When the program finishes the console will close. • Context-sensitive help immediately brings up a relevant help article instead of presenting a list. it must be compiled (or built). the Font window appears. the file it is in.NET. • Dynamic Help and context-sensitive help can also be used with the graphical components in forms. • To create a new project select File>New>New Project. right click the project’s name in the Solution Explorer and se- lect Properties. click in the field next to Text. Name the project and select OK. click and drag one of the form’s enabled sizing handles. © Copyright 1992–2002 by Deitel & Associates. To change the value of this property. • To resize the form.NET generate the remaining code. • After successfully compiling. either select Debug>Start Without Debugging or add a line in the program to wait before exiting.>Visual C# Projects>Windows Application.NET IDE Chapter 2 • After writing code. a new window will appear containing the specified form. • Dynamic help provides a list of helpful articles based on the current context (i. • Regular help.131 Introduction to the Visual Studio. • Double clicking any toolbox control results in a control being created and placed in the corner of the form.e. or perform a search. The specifics of the errors will appear in the Task List at the bottom of the screen. Inc.. The form and Label each have their own Text property—with each being completely independent of the oth- er. the text by the cursor). • The Label’s Text property determines what text (if any) the Label displays. All Rights Reserved.

Open the PictureBox’s Proper- ties window and find the Image attribute. depending on what is highlighted in the Solution Explorer. To execute or run the program. Click the ellipsis button. This places the IDE in design mode.Chapter 2 Introduction to the Visual Studio. A three by three grid of alignment choices will appear. Browse for a picture to insert and press Enter. which opens an Open dialog..NET IDE 132 • The TextAlign property determines how the text is aligned within the Label boundaries. All Rights Reserved.NET cut Debug menu © Copyright 1992–2002 by Deitel & Associates. While in run mode the pro- gram is executing and the user can only interact with a few IDE features.NET clicking Close button icon closing projects code collapsing code summary collapse tree command line argument compile compile errors console application context-sensitive help control customize a form customize VS. 6/29/01 . While in de- sign mode.e. the program is not executing). • The user can save the entire project or just the C# file we created separately. • We have been working in the IDE design mode (i. • Terminate execution by clicking form’s Close button icon or by clicking the tool bar’s End but- ton. Inc. the programmer has access to all the environment windows. • A PictureBox allows us to display an image on the form. The project file contains the names and locations of all the files in the project. By choosing Save All we save both the project and the C# file. click the Start button or select Start from the Debug menu. Features that are not available are disabled and grayed out. corresponding to where the text will appear in the Label. TERMINOLOGY Alignment property Alphabetic icon Appearance property attribute auto-hide window BackColor property background color Backspace key Behavior property build Build menu button Categorized icon Class View window in VS. The C# file contains the source code for the program we just created.

NET Misc property mouse pointer MS Sans Serif new project in VS. 6/29/01 .133 Introduction to the Visual Studio. Inc.NET palette paste © Copyright 1992–2002 by Deitel & Associates.NET opening projects output Output window in VS. All Rights Reserved.NET IDE Chapter 2 delete Delete key design mode double-clicking down arrow down-arrow button dynamic help Dynamic Help window Edit menu enabled sizing handle Enter key expand tree external help File menu find Font property font size font style Font window form background color form title bar Format window graphical user interface (GUI) Height property help filter Help menu help‚ context-sensitive help‚ dynamic help‚ external help‚ internal IDE design mode input integrated development environment (IDE) Intellisense internal help Label Label control Layout property menu menu bar in VS.NET Object Browser window in VS.

compiled into one application.NET Width property window auto-hide window tab Windows application Windows menu writing code SELF-REVIEW EXERCISES 2.Chapter 2 Introduction to the Visual Studio.1 Fill in the blanks in each of the following: a) A _________ application has a GUI.NET Text property title bar tool bar tool tip toolbox in VS. © Copyright 1992–2002 by Deitel & Associates.NET IDE 134 pin a window prepackaged components printing projects project Project menu properties for a form or control Properties window Return key Run menu run mode run program selecting Serif Server Explorer window single-clicking with the left mouse button sizing handle software reuse solution Solution Explorer in VS.NET startup project syntax error syntax highlighting tabbed window Task List in VS.NET View menu visual programming Visual Studio. 6/29/01 . c) The _________ feature saves screen space when the mouse is moved away from a win- dow.NET Tools menu undo View Code in VS. b) A _________ is a group of related files.NET Start button Start Page in VS. All Rights Reserved. Inc.

b) The Start Page allows you to customize the IDE. 2. i) False. Some of the form’s sizing handles are disabled. c) The _________ feature saves screen space when the mouse is moved away from a win- dow. not a searchable index. If false. g) alphabet- ically. The pin icon toggles auto-hide. EXERCISES 2. c) The “x” button toggles auto-hide in most windows. 6/29/01 . 2. e) The tool bar contains the control icons.NET can browse the Internet.2 State whether each of the following is true or false. © Copyright 1992–2002 by Deitel & Associates. b) True. g) The Properties window can be sorted _________ or _________. 2. j) An _________ replaces collapsed code. h) The _________ window allows you to see summary information about classes. a) The title bar displays the mode of the IDE. f) A plus icon indicates that the tree or text can _________. b) project. k) Task List. l) Dynamic help displays a searchable index based on the current context. Dynamic help displays a list relevant of articles. h) Object properties can only be set by writing code. If false. c) auto-hide. l) False. d) tool tip. g) Intellisense provides a list of an object’s available members. b) The Class View window shows more detail than the Object Browser. k) True. c) Visual Studio. g) True. e) Syntax highlighting colors code if it is a _________. d) The tool bar provides a convenient way to execute certain menu commands. j) ellipsis. h) False. i) The _________ has prepackaged components that you can drag and drop onto your form.135 Introduction to the Visual Studio. It can be accessed using the _________ key. Object properties can be set using the Properties window. All Rights Reserved. e) Solution Explorer. but not during execution. f) A form’s sizing handles are always enabled. d) _________ help immediately brings up a relevant article. l) command line ar- guments. The toolbox contains the control icons.3 Fill in the blanks in each of the following: a) The _________ appears in bold in the Solution Explorer window. d) True.2 a) True. A program cannot be run at all if there are compile errors. explain why. k) The Output window displays status information about the program. h) Object Browser.NET IDE Chapter 2 d) A _________ appears when the mouse cursor hovers over an icon. k) Compiling errors are contained in the _________. j) True. l) Console applications may be given _________. a) The Format menu item only appears when in designing a form. d) Visual programming allows you to create complex applications without writing any code. categorically. i) toolbox. f) False.4 State whether each of the following is true or false. e) False.1 a) Windows. f) expand. e) The _________ windows allows you to browse the files in your solution. explain why. c) False. ANSWERS TO SELF-REVIEW EXERCISES 2. Inc. i) Compile errors make a program run more slowly. b) The _________ window allows you to browse components from other computers. j) The grid appears when designing a form.

Execute each program and determine what happens when a control is clicked with the mouse. Explain and give examples of how plus/minus icons. and a RichTextBox.NET.NET was designed this way? 2.5 Some features appear throughout Visual Studio. All Rights Reserved. Why do you think Visual Studio. a) This GUI consists of a MainMenu and a RichTextBox. © Copyright 1992–2002 by Deitel & Associates. yellow background). 2. Add items to the MainMenu by clicking in the “Type Here” section when you insert the component.NET IDE 136 e) Sizing handles are visible during execution.Chapter 2 Introduction to the Visual Studio. ellipsis buttons. Inc.6 Build the following GUIs (you need not provide any functionality). down arrows and tool tips act in this manner. b) This GUI consists of two Labels (font size 12. performing similar methods in differ- ent contexts. 6/29/01 . a MonthCalen- dar.

NET IDE Chapter 2 2. the form and the Properties window are crucial to the concept of visual programming? © Copyright 1992–2002 by Deitel & Associates.7 Consider the differences between a Windows and console application.137 Introduction to the Visual Studio. All Rights Reserved.9 Why do you think that the toolbox. Inc. 6/29/01 . Which one appears more complex? Which seems easier to use? Which might be smaller and more efficient when per- forming the same text-based task? 2.8 Briefly describe each of the following IDE features: a) tool bar b) menu bar c) toolbox d) control e) form f) project g) title bar 2.

NET 117. 119 Close button icon 129 help‚ context-sensitive 120 R closing projects 109 Return key 122 help‚ dynamic 119 code collapsing 115 Run menu 109. 129 control 114 Server Explorer window 113 input 103 customize a form 114 single-clicking with the left mouse integrated development customize VS. 6/29/01 . 120 collapse tree 110 run program 118 command line argument 118 compile 117 I S compile errors 117 IDE (integrated development console application 103 selecting 104 environment) 103 context-sensitive help 120 Serif 125 IDE design mode 128.NET 104 toolbox in VS.NET 107 design mode 109. 109 title bar 105. 124 Start Page in VS.NET 117 E MS Sans Serif 125 Text property 125 Edit menu 105.NET 114 © Copyright 1992–2002 by Deitel & Associates. 117 software reuse 114 internal help 108. Font property 125 118 font size 125 B font style 125 BackColor property 123 Font window 125. 128 help‚ external 108.NET 112 Appearance property 111 opening projects 109 File menu 105. 122. 120 code summary 112 run mode 128 help‚ internal 108. 109 attribute 110 find 109 output 103 auto-hide window 105 Output window in VS. 109 T Misc property 111 tabbed window 106 mouse pointer 106 Task List in VS. 109 button 104 environment (IDE) 103 cut 109 sizing handle 122 Intellisense 116.Index 1 A external help 108. 122. Class View window in VS.NET 126 Height property 110 111 help filter 119 clicking 104 Help menu 109.NET 105. 126 P form background color 123 palette 123 background color 123 form title bar 122 paste 109 Backspace key 122 Behavior property 111 Format window 109 pin a window 106 build 117 prepackaged components 114 Build menu 109 G printing projects 109 button 104 project 104 graphical user interface (GUI) 103 Project menu 109 GUI (graphical user interface) 103 properties for a form or control C 110 Categorized icon 111 H Properties window 110.NET Debug menu 109 L 110 delete 109 Label 125 Start button 128 Delete key 122 Label control 120. 120 O Alignment property 125 Object Browser window in Alphabetic icon 111 F VS. 128 enabled sizing handle 122 tool bar 105 Enter key 122 N tool tip 107 expand tree 110 new project in VS.NET 108. 128 Layout property 111 startup project 110 double-clicking 104 syntax error 116 down arrow 107 syntax highlighting 116 down-arrow button 123 M dynamic help 119 menu 105 Dynamic Help window 119 menu bar in VS. All Rights Reserved. Inc. 120 solution 104 D Solution Explorer in VS.

6/29/01 .NET 115 View menu 105. Inc.NET 103 W Width property 110 window auto-hide 105 window tab 106 Windows application 103 Windows menu 109 writing code 115 © Copyright 1992–2002 by Deitel & Associates.2 Index Tools menu 109 U undo 109 V View Code in VS. 109 visual programming 121 Visual Studio. All Rights Reserved.