Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
C# ПІДРУЧНИКИ / c# / Hungry Minds - Visual C# Blueprint.pdf
Скачиваний:
101
Добавлен:
12.02.2016
Размер:
9.71 Mб
Скачать

C#

VIEW INFORMATION ABOUT WINDOWS FORMS

Soon after Microsoft introduced Windows 3.0, it also released a new version of Basic called Visual Basic. Both the operating system and the programming

language became instant hits; Visual Basic became so popular because you can create a Windows program interface by dragging and dropping interface elements. C# continues this tradition by letting you create forms as an interface for users to enter information.

A form is an area on your screen that presents information to the user of your program so that the user can receive and enter information. Forms can take on several different guises including your standard windows, multiple document

interface, windows, dialog boxes, and surfaces so you can place different objects such as a graphic.

You can add objects such as buttons, controls, and fields into a form by dragging and dropping those elements from a default set of element templates. The form is an instance of a class, and this approach lets you create forms that can inherit from other forms because a class can inherit from another class. The form can inherit from the Form class template or from another form; inheriting from another form gives your form the extensibility it needs to add new features and functionality.

VIEW INFORMATION ABOUT WINDOWS FORMS

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Click Start Programs

 

 

 

 

 

 

 

 

 

The Start page appears.

 

¤ Click Help.

 

Click Index.

 

 

 

 

 

Microsoft Visual Studio .NET

 

 

 

 

 

 

 

 

 

7.0 Microsoft Visual Studio

 

 

 

 

 

 

 

 

 

.NET 7.0.

 

 

 

 

 

 

 

 

 

BUILDING FORMS 10

Microsoft added its form capability that it perfected in Visual Basic into C# as another tool that sets it apart from Visual C++ and Java. (Some Java development tools contain form creation capabilities, however.) Forms are not contained to C# and Visual Basic but are part of the Visual Studio .NET framework so you can import forms from one Visual Studio .NET programming language to another.

Forms act as the user interface for your program so users can interact with your program, the program database, the computer file system, and even the Windows registry. You can write forms in code, but the Windows Forms Designer makes it so easy that you do not have to worry about coding elements in your form.

If you used forms in Visual Basic 6 and want to use the same forms in C#, Visual Studio .NET handles forms differently. The MDE window online help contains a page with a comparison of form changes from Visual Basic 6 to Visual Studio .NET. If you have upgraded to Visual Studio .NET from a version of Visual Studio older than version 6, you can still compare forms in both versions by consulting the comparison help page along with your old Visual Studio documentation.

The Index window appears.

Type forms in the Look for field.

ˇ Click to select Visual C# in the Filtered by drop-down list.

Á Scroll down the topics list until you reach the overview topic.

Click the overview topic.

The Introduction to Windows Forms page appears so you can read more information about Windows forms.

197

C#

ADD A WINDOWS FORM IN THE WINDOWS FORM DESIGNER

You add Visual Studio .NET forms — what Microsoft terms Windows forms — in C# by using the Windows Form Designer. In many cases you do not have to

create a Windows form from scratch because C# creates one for you automatically when you open a new project, thus saving you time.

The form appears in the parent window so you can edit its properties and add information to the form. Form properties appear in the Properties window. If you add a new form in the Windows Form Designer, then the new form will appear in its own window with its own name.

When you view the form for the first time, you will notice that the form has dots throughout the form. These dots represent the grid, and you can use these dots as boundaries for objects that you add to the form. The gridlines help ensure that all the objects in your form look pleasing to the eye and that form objects do not interlap.

A box comprised of dashed lines appears around the perimeter of the form. This selection box lets you know that the current form is selected. The white boxes that appear within the selection box are the form handles. You can use these handles for resizing your form until it is the size you want.

ADD A WINDOWS FORM

Click the Windows Application icon in the Templates pane.

Type a name for the file.

ˇ Click OK.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Á Right-click FormOne in

 

 

 

 

 

 

 

 

 

 

Click Add.

the Solution Explorer

 

° Click Add Windows Form.

window.

 

 

 

 

 

 

BUILDING FORMS 10

Your new form already contains all the standard elements of a Windows form including a title bar. From left to right, the title bar contains a multicolored logo for performing window functions. This built-in function makes it easier for you to program your form and gives the user a familiar, standard interface for your program.

You can program in code if you want to, but if you are uncertain about how to proceed, you can create a form and then view the underlying code to see the nuts and bolts of your form. In the Solution Explorer window, you can click the form with your right mouse button. In the pop-up menu that appears, click View Code. A new window appears that contains the code for your form. You can go back to the designer by clicking the form tab with the [Design] label after the form name.

Form2.cs

 

 

 

 

 

 

 

Save the program as the

The Add New Item

 

 

 

The new form appears in

 

 

 

 

 

 

Click Open.

window appears.

 

 

 

the parent window.

filename.

 

· Type the new form name

 

 

 

 

 

 

 

 

 

 

 

in the Name field.

 

 

 

 

 

199

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