There are many versions of Visual Studio available. For this book, we used the Microsoft Visual C# 2005 Express Edition, which supports only the Visual C# programming language. Microsoft also offers a full version of Visual Studio 2005, which includes support for other languages in addition to Visual C#, such as Visual Basic and Visual C++. Our screen captures and discussions focus on the IDE of the Visual C# 2005 Express Edition. We assume that you have some familiarity with Windows.
Again, we use fonts to distinguish between IDE features (such as menu names and menu items) and other elements that appear in the IDE. We emphasize IDE features in a sans-serif bold Helvetica font (e.g., File menu) and emphasize other elements, such as file names (e.g., Form1.cs) and property names (discussed in Section 2.4), in a sans-serif Lucida font.
Introduction to Microsoft Visual C# 2005 Express Edition
To start Microsoft Visual C# 2005 Express Edition in Windows XP, select Start > All Programs > Visual C# 2005 Express Edition. For Windows 2000 users, select Start > Programs > Visual C# 2005 Express Edition. Once the Express Edition begins execution, the Start Page displays (Fig. 2.1). Depending on your version of Visual Studio, your Start Page may look different. For new programmers unfamiliar with Visual C#, the Start Page contains a list of links to resources in the Visual Studio 2005 IDE and on the Internet. From this point forward, we will refer to the Visual Studio 2005 IDE simply as "Visual Studio" or "the IDE." For experienced developers, this page provides links to the latest developments in Visual C# (such as updates and bug fixes) and to information on advanced programming topics. Once you start exploring the IDE, you can return to the Start Page by selecting the page from the location bar drop-down menu (Fig. 2.2), by selecting View > Other Windows > Start Page or by clicking the Start Page icon from the IDE's Toolbar (Fig. 2.9). We discuss the Toolbar and its various icons in Section 2.3. We use the > character to indicate the selection of a menu command from a menu. For example, we use the notation File > Open File to indicate that you should select the Open File command from the File menu.
Figure 2.1. Start Page in Visual C# 2005 Express Edition.
Figure 2.2. Displaying a Web page in Visual Studio.
(This item is displayed on page 38 in the print version)
Links on the Start Page
The Start Page links are organized into sectionsRecent Projects, Getting Started, Visual C# Express Headlines and MSDN: Visual Studio 2005that contain links to helpful programming resources. Clicking any link on the Start Page displays the relevant information associated with the specific link. We refer to single clicking with the left mouse button as selecting or clicking;we refer to double clicking with the left mouse button simply as double clicking.
The Recent Projects section contains information on projects you have recently created or modified. You can also open existing projects or create new ones by clicking the links in the section. The Getting Started section focuses on using the IDE to create programs, learning Visual C#, connecting to the Visual C# developer community (i.e., other software developers with whom you can communicate through newsgroups and Web sites) and providing various development tools such as starter kits. For example, clicking the link Use a Starter Kit provides you with resources and links for building a simple screen saver application or a movie collection application. The screen saver application builds a screen saver that displays current news articles. The movie collection starter kit builds an application that lets you maintain a catalog of your DVDs and VHS movies, or the application can be changed to track anything else you might collect (e.g., CDs, video games).
The Visual C# Express Headlines and MSDN: Visual Studio 2005 sections provide links to information about programming in Visual C#, including a tour of the language, new Visual C# 2005 features and online courses. To access more extensive information on Visual Studio, you can browse the MSDN (Microsoft Developer Network) online library at msdn.microsoft.com. The MSDN site contains articles, downloads and tutorials on technologies of interest to Visual Studio developers. You can also browse the Web from the IDE using Internet Explorer. To request a Web page, type its URL into the location bar (Fig. 2.2) and press the Enter keyyour computer, of course, must be connected to the Internet. (If the location bar is not already present in the IDE, select View > Other Windows > Show Browser.) The Web page that you wish to view will appear as another tab, which you can select, inside the Visual Studio IDE (Fig. 2.2).
Customizing the IDE and Creating a New Project
To begin programming in Visual C#, you must create a new project or open an existing one. There are two ways to create a new project or open an existing project. You can select either File > New Project... or File > Open Project... from the File menu, which creates a new project or opens an existing project, respectively. From the Start Page, under the Recent Projects section, you can also click the links Create: Project or Open: Project/Solution. A project is a group of related files, such as the Visual C# code and any images that might make up a program. Visual Studio 2005 organizes programs into projects and solutions, which contain one or more projects. Multiple-project solutions are used to create large-scale programs. Each of the programs we create in this book consists of a single project.
Select File > New Project... or the Create: Project... link on the Start Page to display the New Project dialog (Fig. 2.3). Dialogs are windows that facilitate user-computer communication. We will discuss the detailed process of creating new projects momentarily.
Figure 2.3. New Project dialog.
Visual Studio provides templates for several project types (Fig. 2.3). Templates are the project types users can create in Visual C#Windows applications, console applications and others (you will primarily use Windows applications and console applications in this textbook). Users can also use or create custom application templates. In this chapter, we focus on Windows applications. We discuss the Console Application template in Chapter 3, Introduction to C# Applications. A Windows application is a program that executes within a Windows operating system (e.g., Windows 2000 or Windows XP) and typically has a graphical user interface (GUI)the visual part of the program with which the user interacts. Windows applications include Microsoft software products like Microsoft Word, Internet Explorer and Visual Studio; software products created by other vendors; and customized software that you and other programmers create. You will create many Windows applications in this text. [Note: Novell sponsors an open source project called Mono that enables developers to create .NET applications for Linux, Windows and Mac OS X. Mono is based on the Ecma standards for C# and the Common Language Infrastructure (CLI). For more information on Mono, visit www.mono-project.com.]
By default, Visual Studio assigns the name WindowsApplication1 to the new project and solution (Fig. 2.3). Soon you will change the name of the project and the location where it is saved. Click OK to display the IDE in design view (Fig. 2.4), which contains all the features necessary for you to begin creating programs. The design view portion of the IDE is also known as the Windows Form Designer.
Figure 2.4. Design view of the IDE.
The gray rectangle titled Form1 (called a Form) represents the main window of the Windows application that you are creating. C# applications can have multiple Forms (windows); however, most of the applications you will create in this text use only one Form. Later in the chapter, you will learn how to customize the Form by adding controls (i.e., reusable components) to a programin this case, a Label and a PictureBox (as you will see in Fig. 2.27). A Label typically contains descriptive text (e.g., "Welcome to Visual C#!"), and a PictureBox displays images, such as the Deitel bug mascot. Visual Studio has over 65 preexisting controls you can use to build and customize your programs. Many of these controls are defined and used throughout this book. In addition to the controls provided with Visual C# 2005 Express or Visual Studio 2005, there are many other controls available from third parties. You can download several third party controls from msdn.microsoft.com/vcsharp/downloads/components/default.aspx.
As you begin programming, you will work with controls that are not necessarily part of your program, but rather are part of the FCL. As you place controls on the form, you can modify their properties (discussed in detail in Section 2.4) by entering alternative text in a text box (Fig. 2.5) or selecting options then pressing a button, such as OK or Cancel, as shown in Fig. 2.6.
Figure 2.5. Example of a text box control in the Visual Studio IDE.
Figure 2.6. Examples of buttons in the Visual Studio IDE.
(This item is displayed on page 42 in the print version)
Collectively, the Form and controls constitute the program's GUI. Users enter data (input) into the program in a variety of ways, including typing at the keyboard, clicking the mouse buttons and typing into GUI controls, such as TextBoxes. Programs use the GUI to display instructions and other information (output) for users to read. For example, the New Project dialog in Fig. 2.3 presents a GUI where the user clicks the mouse button to select a project template, then inputs a project name from the keyboard (note that the figure is still showing the default project name WindowsApplication1 supplied by Visual Studio).
The name of each open document is listed on a tabin Fig. 2.4, the open documents are Form1.cs [Design] and the Start Page. To view a document, click its tab. Tabs facilitate easy access to multiple open documents. The active tab (the tab of the document currently displayed in the IDE) is displayed in bold text (e.g., Form1.cs [Design] in Fig. 2.4) and is positioned in front of all the other tabs.
Introduction to Computers, the Internet and Visual C#
Introduction to the Visual C# 2005 Express Edition IDE
Introduction to C# Applications
Introduction to Classes and Objects
Control Statements: Part 1
Control Statements: Part 2
Methods: A Deeper Look
Classes and Objects: A Deeper Look
Object-Oriented Programming: Inheritance
Polymorphism, Interfaces & Operator Overloading
Graphical User Interface Concepts: Part 1
Graphical User Interface Concepts: Part 2
Strings, Characters and Regular Expressions
Graphics and Multimedia
Files and Streams
Extensible Markup Language (XML)
Database, SQL and ADO.NET
ASP.NET 2.0, Web Forms and Web Controls
Networking: Streams-Based Sockets and Datagrams
Searching and Sorting
Appendix A. Operator Precedence Chart
Appendix B. Number Systems
Appendix C. Using the Visual Studio 2005 Debugger
Appendix D. ASCII Character Set
Appendix E. Unicode®
Appendix F. Introduction to XHTML: Part 1
Appendix G. Introduction to XHTML: Part 2
Appendix H. HTML/XHTML Special Characters
Appendix I. HTML/XHTML Colors
Appendix J. ATM Case Study Code
Appendix K. UML 2: Additional Diagram Types
Appendix L. Simple Types