Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Учебник_ПОА.doc
Скачиваний:
93
Добавлен:
13.02.2015
Размер:
2.65 Mб
Скачать

Компиляция кода

Для этого примера необходимы следующие компоненты.

  • Проект приложения Windows Forms с формой, имеющей имя formGraphics.

Код должен находиться внутри области действия класса Form. Экземпляр формы представлен this.

Надежное программирование

Для любого объекта, потребляющего системные ресурсы (например, для объектов Brush и Graphics), всегда нужно вызывать метод Dispose.

How to: Draw a Line on a Form

This example demonstrates how to draw a line on a form.

Example

System.Drawing.Pen myPen;

myPen = new System.Drawing.Pen(System.Drawing.Color.Red);

System.Drawing.Graphics formGraphics = this.CreateGraphics();

formGraphics.DrawLine(myPen, 0, 0, 200, 200);

myPen.Dispose();

formGraphics.Dispose();

Compiling the Code

This example requires:

  • A Windows Forms Application project with a form named formGraphics.

The code must be within the scope of the Form class. The instance of the form is represented by this.

Robust Programming

You should always call Dispose on any objects that consume system resources, such as Brush and Graphics objects.

Рисование линии в форме

В этом примере показано, как нарисовать линию в форме.

Пример24

System.Drawing.Pen myPen;

myPen = new System.Drawing.Pen(System.Drawing.Color.Red);

System.Drawing.Graphics formGraphics = this.CreateGraphics();

formGraphics.DrawLine(myPen, 0, 0, 200, 200);

myPen.Dispose();

formGraphics.Dispose();

Компиляция кода

Для этого примера необходимы следующие компоненты.

  • Проект приложения Windows Forms с формой, имеющей имя formGraphics.

Код должен находиться внутри области действия класса Form. Экземпляр формы представлен this.

Надежное программирование

Для любого объекта, потребляющего системные ресурсы (например, для объектов Brush и Graphics), всегда нужно вызывать метод Dispose.

How to: Draw a Filled Rectangle on a Form

This example demonstrates how to draw a filled rectangle on a form.

Example

System.Drawing.SolidBrush brush1 =

new System.Drawing.SolidBrush(System.Drawing.Color.Red);

System.Drawing.Graphics formGraphics = this.CreateGraphics();

formGraphics.FillRectangle(brush1, new System.Drawing.Rectangle(0,0,200,300));

brush1.Dispose();

formGraphics.Dispose();

Compiling the Code

This example requires:

  • A Windows Forms Application project with a form named formGraphics.

The code must be in the scope of the Form class. The instance of the form is represented by this.

Robust Programming

You should always call Dispose on any objects that consume system resources, such as Brush and Graphics objects

Рисование заполненного прямоугольника в форме

В этом примере показано, как в форме нарисовать заполненный прямоугольник.

Пример25

System.Drawing.SolidBrush brush1 =

new System.Drawing.SolidBrush(System.Drawing.Color.Red);

System.Drawing.Graphics formGraphics = this.CreateGraphics();

formGraphics.FillRectangle(brush1, new System.Drawing.Rectangle(0,0,200,300));

brush1.Dispose();

formGraphics.Dispose();

Компиляция кода

Для этого примера необходимы следующие компоненты.

  • Проект приложения Windows Forms с формой, имеющей имя formGraphics.

Код должен находиться в области действия класса Form. Экземпляр формы представлен this.

Надежное программирование

Для любого объекта, потребляющего системные ресурсы (например, для объектов Brush и Graphics), всегда нужно вызывать метод Dispose.

How to: Draw a Filled Ellipse on a Form

This example demonstrates how to draw a filled ellipse on a form.

Example

System.Drawing.SolidBrush brush1 =

new System.Drawing.SolidBrush(System.Drawing.Color.Red);

System.Drawing.Graphics formGraphics = this.CreateGraphics();

formGraphics.FillEllipse(brush1, new System.Drawing.Rectangle(0,0,200,300));

brush1.Dispose();

formGraphics.Dispose();

Compiling the Code

This example requires:

  • A Windows Forms Application project with a form named formGraphics.

The code must be in the scope of the form class. The instance of the form is represented by this.

Robust Programming

You should always call Dispose on any objects that consume system resources, such as Brush and Graphics objects.

Рисование заполненного эллипса в форме

В этом примере показано, как в форме нарисовать заполненный эллипс.

Пример26

System.Drawing.SolidBrush brush1 =

new System.Drawing.SolidBrush(System.Drawing.Color.Red);

System.Drawing.Graphics formGraphics = this.CreateGraphics();

formGraphics.FillEllipse(brush1, new System.Drawing.Rectangle(0,0,200,300));

brush1.Dispose();

formGraphics.Dispose();

Компиляция кода

Для этого примера необходимы следующие компоненты.

  • Проект приложения Windows Forms с формой, имеющей имя formGraphics.

Код должен находиться в области действия класса form. Экземпляр формы представлен this.

Надежное программирование

Для любого объекта, потребляющего системные ресурсы (например, для объектов Brush и Graphics), всегда нужно вызывать метод Dispose.

Adding Multimedia to an Application

You can enhance applications by adding multimedia components such as audio, video, and graphic files. This section provides links to topics that describe common programming tasks for adding multimedia to an application.

How to: Embed Windows Media Player on a Form

You can embed Windows Media Player in a Windows form to provide multimedia in your application. You must first add the Windows Media Player COM control to the toolbox, and then you can add the control to your application.

To Add the Windows Media Player Control to the Toolbox

  1. On the File menu, click New Project.

  2. In the New Project dialog box, click Windows Forms Application, and then click OK.

A new Windows Forms project opens.

  1. Right-click the Toolbox, and click Choose Items.

    Note:

    If you do not see the Toolbox, click Toolbox on the View menu to open it.

  2. The Customize Toolbox Items dialog box opens.

  3. On the COM Components tab, select the Windows Media Player check box, and then click OK.

  4. The Windows Media Player control appears on the current Toolbox tab.

When you add the Windows Media Player control to the Toolbox, Visual Studio automatically adds references to two libraries: AxWMPLib and WMPLib. The next step is to add the control to the Windows Form.