• No results found

Chapter Objectives:

In document c#.net (Page 30-34)

Create a simple Windows application

Add controls using the Toolbox

Configure controls using Properties

Write code to respond to user actions

Use context-sensitive help

2.1 Creating a Windows Application

We show how to use Visual Studio .NET to begin creating a simple Win-dows application.

2.1.1 The Start Page

Visual Studio .NET opens by default with a Start Page, as shown in Figure 2.1.

We can change the default by choosing the Tools, Options menu item. In the upper-right corner, we can pop up the following choices:

Show Start Page

Load last loaded solution Show Open Project dialog box

Figure 2.1 The Start Page.

Show New Project dialog box Show empty environment

2.1.2 Creating a Project

To create a new project we click the New Project button, choosing Visual C#

Projectsas the project type and the Windows Applicationtemplate. Templates provide the correct starting environment for the type of project we are building. The various project types with their accompanying descriptions are:

Windows Application A project for creating an application with a Windows user interface

Class Library A project for creating classes to use in other applications

Windows Control Library A project for creating controls to use in Win-dows applications

Mobile Web Application A project for creating an application viewable on PDAs, cell phones, and other mobile devices

2.1 Creating a Windows Application 17

ASP.NET Web Application A project for creating an application with a Web user interface

ASP.NET Web Service A project for creating XML Web services to use from other applications

Web Control Library A project for creating controls to use in Web applications

Console Application A project for creating a command-line application

Windows Service A project for creating services for Windows

Empty Project An empty project for creating a local application

Empty Web Project An empty project for creating a Web Application

New Project in An empty project created in an existing folder

Existing Folder

We will use some of these templates later in the text. Later versions of Visual Studio .NET include a few additional choices. The Mobile Web Appli-cationtemplate requires a separate download to install in earlier versions.

For the Windows application we are creating, we choose the name Exam-ple2-1and the location c:\booknet\ch2, and click OK. The location is the folder in which all the files for this project will be stored.

2.1.3 The Properties Window

Figure 2.2 shows the form on the left with the Propertieswindow on the right. If the Propertieswindow does not appear, we can view it by clicking the View, Properties Window menu item.

The form in Figure 2.2 has a grid of dots that we can use to align controls that we add to the form. Using the scroll bar in thePropertieswindow, we can explore the various properties that we can use to configure the form. The mainPropertiescategories for aFormareAccessibility,Appearance,Behavior,

Configurations,Data,Design,Focus,Layout,Misc, andWindow Style. If they show with a plus sign (+)at the left, clicking on the plus sign will open a list of properties in that category. Figure 2.2 shows theAppearance properties. The highlighted property,Text, has its description below theProperties window.

In thePropertieswindows, the row just below the name,Form1, contains five buttons. The leftmost two, separated by a vertical bar from the rest, allow us to choose to arrange the properties by category or alphabetically. The left button of these two, for categories, is the default. The second group of two buttons lets us choose this window to display property values or event

Figure 2.2 A Windows application.

methods. The default is property values. We will discuss event methods later and use another approach to define them. We stick with the default choice of property values. The rightmost button, for Property Pages, is disabled.

2.1.4 Changing Properties

The Text property contains the title of the application. It appears in the frame of the form. We can replace the default text,Form1, with our own title.

We type A Simple Form, and after pressing the Enter key this text appears as the new title in the form.

We use the BackColorproperty to change the background color of the form.

The current color is a gray, which is the default for a Control. If we click on this current BackColorvalue we get a combo box with an arrow to allow us to pop up a window with three tabs,Custom,Web, and System. The Systemtab is on top and shows the default color for various system elements. We could selectControlLightorControlLightLightto get a lighter color for the form background, but we select the Customtab to get a grid of custom color selec-tions. We choose the fourth color in the top row, which is a light pinkish yellow. The numbers 255, 255, and 192 associated with this color represent

Visual Studio .NET opens with a Startpage that we can configure in various styles. We begin by creat-ing a project of which there are several types. A Win-dows application provides aFormfor creating a user interface. A Properties

its red, green, and blue components on a scale from 0 to 255, with 255 being the most intense.

We can use properties to specify the size and the location of the form. We use pixels to indicate size and location. A pixel is a picture element, a single dot on the screen. The screen resolution determines the number of pixels for the full screen. Some usual configurations are 800 by 600 or 1024 by 768, where the first measurement is the number of pixels making up the width and the second is the height.

In document c#.net (Page 30-34)

Related documents