30.07.2013 Views

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 16 Graphics and Multimedia 705<br />

Lines 30–32 perform similar functions, except that the specified arc sweeps -270<br />

degrees. The Size property of a Rectangle determines the arc’s height and width. Line<br />

36 sets the Size property <strong>to</strong> a new Size object, which changes the size of the rectangle.<br />

The remainder of the program is similar <strong>to</strong> the portions described above, except that a<br />

SolidBrush is used with method FillPie. The resulting arcs, which are filled, can be<br />

seen in the bot<strong>to</strong>m half of the screenshot Fig. 16.18.<br />

16.7 Drawing Polygons and Polylines<br />

Polygons are multisided shapes. There are several Graphics methods used <strong>to</strong> draw polygons:<br />

DrawLines draws a series of connected points, DrawPolygon draws a closed<br />

polygon and FillPolygon draws a solid polygon. These methods are described in<br />

Fig. 16.19. The program in Fig. 16.20 allows users <strong>to</strong> draw polygons and connected lines<br />

via the methods listed in Fig. 16.19.<br />

Method Description<br />

DrawLines Draws a series of connected lines. The coordinates of each point are specified<br />

in an array of Points. If the last point is different from the first point,<br />

the figure is not closed.<br />

DrawPolygon Draws a polygon. The coordinates of each point are specified in an array of<br />

Point objects. This method draws a closed polygon, even if the last point<br />

is different from the first point.<br />

FillPolygon Draws a solid polygon. The coordinates of each point are specified in an<br />

array of Points. This method draws a closed polygon, even if the last<br />

point is different from the first point.<br />

Fig. 16.19 Graphics methods for drawing polygons.<br />

1 ' Fig. 16.20: DrawPolygons.vb<br />

2 ' Demonstrating polygons.<br />

3<br />

4 Public Class FrmPolygon<br />

5 Inherits System.Windows.Forms.Form<br />

6<br />

7 ' polygon type options<br />

8 Friend WithEvents filledPolygonRadio As RadioBut<strong>to</strong>n<br />

9 Friend WithEvents lineRadio As RadioBut<strong>to</strong>n<br />

10 Friend WithEvents polygonRadio As RadioBut<strong>to</strong>n<br />

11<br />

12 ' command but<strong>to</strong>ns<br />

13 Friend WithEvents cmdClear As But<strong>to</strong>n<br />

14 Friend WithEvents cmdNewColor As But<strong>to</strong>n<br />

15<br />

16 Friend WithEvents drawWindow As Panel<br />

17 Friend WithEvents typeGroup As GroupBox<br />

Fig. 16.20 Polygon drawing demonstration (part 1 of 4).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!