Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
C# ПІДРУЧНИКИ / c# / Manning - Windows.forms.programming.with.c#.pdf
Скачиваний:
108
Добавлен:
12.02.2016
Размер:
14.98 Mб
Скачать

SET THE VERSION NUMBER FOR THE MYPHOTOS PROJECT (continued)

 

Action

Results

 

 

 

5

Locate the Form1

public Form1

 

constructor.

{

 

 

. . .

 

 

 

6

At the end of the

// Set the application title bar

 

constructor, add code to

Version ver

 

include the version number

= new Version(Application.ProductVersion);

 

 

 

in the title bar.

this.Text = String.Format("MyPhotos {0:#}.{1:#}",

 

 

ver.Major, ver.Minor);

 

 

}

 

 

Note: This code uses the Version class to decode the

 

 

version string. The constructor of this class accepts a

 

 

string and provides access to the individual parts of the

 

 

corresponding version number.

 

 

 

In your applications, you can set the build and revision numbers explicitly, or have

.NET generate them automatically. We will change the version number repeatedly throughout this book as a way to indicate which section of the book corresponds to the current application. You can change or not change the version number as you wish. On the book’s web site, these version numbers are used to identify the file associated with a specific section.

In your own applications, a version number identifies a specific instance of a product that your customers or friends are using. This is useful for documentation and support reasons, and for indicating to your customers when new features and functionality are added to a product. Note that it is common practice to include the version number in a dialog box, often called an About box, that is available from a top-level Help menu in an application.

Of course, the class Form1 is not the most descriptive name, so let’s rename this class next.

2.2.2Renaming a form

One other change before we add some controls to our form. Visual Studio created the class Form1 in our project. Let’s rename this file and associated class to MainForm.

46

CHAPTER 2 GETTING STARTED WITH VISUAL STUDIO .NET

RENAME THE FORM1 CLASS AND FILE TO MAINFORM

 

Action

Result

 

 

 

1

Rename the Form1.cs file in

The file is renamed. The designer and code windows are

 

the Solution Explorer window

also renamed to reflect the new file name.

 

to MainForm.cs.

 

 

How-to

 

 

a. Right-click the Form1.cs file

 

 

in the Solution Explorer

 

 

window.

 

 

b. Select the Rename item.

 

 

c. Type the new name “Main-

 

 

Form.cs” for the file.

 

 

d. Press the Enter key.

 

 

 

 

2

If not already shown, display

 

 

the MainForm.cs window

 

 

containing our source code.

 

 

How-to

 

 

Click the MainForm.cs tab in

 

 

the main window.

 

 

 

 

3

Replace all occurrences of the

The Replace dialog box should appear as follows.

 

string “Form1” with

 

 

“MainForm.”.

 

 

How-to

 

 

a. Type the Ctrl+H key to dis-

 

 

play the Replace dialog.

 

 

b. Type “Form1” for the Find

 

 

what: text and “MainForm”

 

 

for the Replace with text,

 

 

as shown in the graphic.

 

 

c. Click the Replace All

After the Replace All button is clicked, all four occurrences

 

button.

of the string are replaced in the code.

 

Note: The Ctrl+H key is a

 

 

shortcut for the Replace

 

 

menu item located in the

 

 

Find and Replace submenu

 

 

under the top-level Edit

 

 

menu.

 

 

 

 

4

Click the Close button.

The Replace dialog disappears.

 

 

 

With an explanation of versions and the renaming of our main form out of the way, we can get back to the topic of placing controls on our form.

ADDING CONTROLS

47

Соседние файлы в папке c#