|
|
 |
 |
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
(Publisher: The Coriolis Group)
Author(s): Steven Holzner
ISBN: 1576102831
Publication Date: 08/01/98
Drawing Points
To draw individual points, you use PSet in forms and picture boxes like this:
object.PSet [Step] ( x, y), [color]
Here are the arguments you pass to PSet:
- StepKeyword specifying that the coordinates are relative to the current graphics position given by the CurrentX and CurrentY properties.
- x, ySingle values indicating the horizontal (x-axis) and vertical (y-axis) coordinates of the point to set.
- colorLong integer value indicating the RGB color specified for the point. If omitted, the current ForeColor property setting is used. You can use the RGB function or QBColor function to specify the color.
You can also use the Point method to retrieve the color of a point at a specific (x, y) location.
Setting The Drawing Mode
You draw with pens in Windows. Every drawing operation uses these pens. When you set the drawing width, youre really setting the width of the pen; when you set the drawing color, youre setting the color of the pen.
You can also use the DrawMode property to specify how the current pen interacts with the graphics it already finds in a form or picture box. Here are the possible settings for the pens drawing mode:
- vbBlackness1, Blackness
- vbNotMergePen2, Not Merge Pen; inverse of setting 15 (Merge Pen)
- vbMaskNotPen3, Mask Not Pen; combination of the colors common to the background color and the inverse of the pen
- vbNotCopyPen4, Not Copy Pen; inverse of setting 13 (Copy Pen)
- vbMaskPenNot5, Mask Pen Not; combination of the colors common to both the pen and the inverse of the display
- vbInvert6, Invert; inverse of the display color
- vbXorPen7, XOR Pen; combination of the colors in the pen and in the display color, but not in both
- vbNotMaskPen8, Not Mask Pen; inverse of setting 9 (Mask Pen)
- vbMaskPen9, Mask Pen; combination of the colors common to both the pen and the display
- vbNotXorPen10, Not XOR Pen; inverse of setting 7 (XOR Pen)
- vbNop11 Nop, No operation; output remains unchanged (in effect, this setting turns drawing off)
- vbMergeNotPen12, Merge Not Pen; combination of the display color and the inverse of the pen color
- vbCopyPen13, Copy Pen (the default); color specified by the ForeColor property
- vbMergePenNot14, Merge Pen Not; combination of the pen color and the inverse of the display color
- vbMergePen15, Merge Pen; combination of the pen color and the display color
- vbWhiteness16, Whiteness
For example, we can set the pen to be an invert pen with this code and draw over some lines. The pen will invert the pixels it finds:
Private Sub Form_Load()
Dim intLoopIndex As Integer
For intLoopIndex = 1 To 9
DrawWidth = intLoopIndex
Line (0, intLoopIndex * ScaleHeight / 10)(ScaleWidth, _
intLoopIndex * ScaleHeight / 10)
Next intLoopIndex
DrawMode = vbInvert
DrawWidth = 10
Line (0, 0)-(ScaleWidth, ScaleHeight)
Line (0, ScaleHeight)-(ScaleWidth, 0)
End Sub
The result of this code appears in Figure 18.13; the two diagonal lines are drawn with the inverted pen.
Figure 18.13 Drawing with the Invert pen.
TIP: The XOR (exclusive OR) pen is a popular one, because when you draw with it twice in the same location, the display is restored to its original condition. This happens because if you XOR number A to number B twice, number B is restored. Programmers use this to draw figures they know theyll need to erase, such as when letting the user stretch a graphics figure with the mouse. In such a case, each figure you draw will have to be erased before you can draw the next one to give the illusion of stretching the figure. What programmers usually do is to draw the stretched figure with the XOR pen, and when its time to erase it, they draw it again with the same pen, thereby restoring the screen.
The code for this example is located in the drawinvert folder on this books accompanying CD-ROM.
|