19.12.2012 Views

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

EXAMPLE 3<br />

Write a program to draw the sector consisting of the bottom half of a circle <strong>and</strong> fill it with vertical lines.<br />

SOLUTION:<br />

Vertical lines correspond to a FillStyle of 3. See Figure 9-21 for the output of the following program.<br />

Private Sub cmdDraw_Click()<br />

Dim c As Single<br />

‘Draw bottom half of circle filled with vertical lines<br />

c = 2 * 3.14159<br />

picSector.Cls<br />

picSector.Scale (-3, 3)-(3, -3) ‘Specify coordinate system<br />

picSector.FillStyle = 3 ‘Vertical lines<br />

picSector.Circle (0, 0), 2, , -.5 * c, -1 * c<br />

End Sub<br />

FIGURE 9-21 Display from Example 3<br />

The color used to fill the interior of a sector is determined by the value of the FillColor<br />

property. If the FillStyle of a picture box is any value except 1, then the statement<br />

picBox.FillColor = vbColor<br />

where vbColor is a color constant, will cause new circles <strong>and</strong> sectors drawn in the picture box<br />

to be filled with a colored pattern.<br />

EXAMPLE 4<br />

Write a program to subdivide a circle into four quadrants <strong>and</strong> fill in the second quadrant, that is, the quadrant<br />

extending from radius line .25 to radius line .5, with magenta crosshatched lines.<br />

SOLUTION:<br />

Crosshatched lines correspond to a FillStyle of 6. See Figure 9-22 for the output of the following program.<br />

Private Sub cmdDraw_Click()<br />

Dim c As Single<br />

‘Draw quarters of circle <strong>and</strong> paint upper-left quadrant<br />

c = 2 * 3.14159<br />

picBox.Cls picBox.Scale (-3, 3)-(3, -3) ‘Specify coordinate system<br />

picBox.Circle (0, 0), 2, , -.0000001 * c, -.25 * c<br />

picBox.FillStyle = 6 ‘Crosshatched<br />

picBox.FillColor = vbMagenta<br />

picBox.Circle (0, 0), 2, , -.25 * c, -.5 * c<br />

picBox.FillStyle = 1 ‘Transparent<br />

picBox.Circle (0, 0), 2, , -.5 * c, -.75 * c<br />

picBox.Circle (0, 0), 2, , -.75 * c, -1 * c<br />

End Sub<br />

FIGURE 9-22 Display from Example 4<br />

Pie Charts 279

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

Saved successfully!

Ooh no, something went wrong!