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.

(c) The point (–2, 0) is the left-h<strong>and</strong> end point of the x axis<br />

<strong>and</strong> the point (10, 0) is the right-h<strong>and</strong> end point; therefore,<br />

the line joining them is just the portion of the x axis<br />

we have already drawn.<br />

We draw these graphs on the screen with the same three steps we use with paper, pencil,<br />

<strong>and</strong> ruler. The only difference is that we first do Step 2 <strong>and</strong> then Steps 1 <strong>and</strong> 3. The <strong>Visual</strong><br />

<strong>Basic</strong> method Scale is used to specify the range of values for the axes <strong>and</strong> the method Line<br />

serves as the ruler.<br />

The statement<br />

picBox.Scale (a, d)-(b, c)<br />

specifies that numbers on the x axis range from a to b <strong>and</strong> that numbers on the y axis range<br />

from c to d. See Figure 9-2. The ordered pair (a, d) gives the coordinates of the top left corner<br />

of the picture box, <strong>and</strong> the ordered pair (b, c) gives the coordinates of the bottom right corner<br />

of the picture box.<br />

FIGURE 9-2 Result of Scale Method FIGURE 9-3 Result of the Line Method<br />

■ GRAPHICS METHODS FOR DRAWING LINES, POINTS, AND CIRCLES<br />

After an appropriate coordinate system has been specified by a picBox.Scale statement, graphics<br />

can be drawn in the picture box using the Line <strong>and</strong> Circle methods. The statement<br />

picBox.Line (x1, y1)-(x2, y2)<br />

draws the line segment from the point with coordinates (x1, y1) to the point with coordinates<br />

(x2, y2) in the picture box (see Figure 9-3). In particular, the statement picBox.Line (a, 0)–(b,<br />

0) draws the x axis <strong>and</strong> the statement picBox. Line (0, c)–(0, d) draws the y axis.<br />

The following event procedure produces the graph of Example 1, part (b):<br />

Private Sub cmdDraw_Click()<br />

picOutput.Cls picOutput.Scale (-2, 18)-(10, -3) ‘Specify coordinate system<br />

picOutput.Line (-2, 0)-(10, 0) ‘Draw x-axis<br />

picOutput.Line (0, -3)-(0, 18) ‘Draw y-axis<br />

picOutput.Line (1, 15)-(8, 6) ‘Draw the straight line<br />

End Sub<br />

Introduction to Graphics 261

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

Saved successfully!

Ooh no, something went wrong!