Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
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

Bookmark It

Search this book:
 
Previous Table of Contents Next


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:

  Step—Keyword 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, you’re really setting the width of the pen; when you set the drawing color, you’re 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 pen’s drawing mode:

  vbBlackness—1, Blackness
  vbNotMergePen—2, Not Merge Pen; inverse of setting 15 (Merge Pen)
  vbMaskNotPen—3, Mask Not Pen; combination of the colors common to the background color and the inverse of the pen
  vbNotCopyPen—4, Not Copy Pen; inverse of setting 13 (Copy Pen)
  vbMaskPenNot—5, Mask Pen Not; combination of the colors common to both the pen and the inverse of the display
  vbInvert—6, Invert; inverse of the display color
  vbXorPen—7, XOR Pen; combination of the colors in the pen and in the display color, but not in both
  vbNotMaskPen—8, Not Mask Pen; inverse of setting 9 (Mask Pen)
  vbMaskPen—9, Mask Pen; combination of the colors common to both the pen and the display
  vbNotXorPen—10, Not XOR Pen; inverse of setting 7 (XOR Pen)
  vbNop—11 Nop, No operation; output remains unchanged (in effect, this setting turns drawing off)
  vbMergeNotPen—12, Merge Not Pen; combination of the display color and the inverse of the pen color
  vbCopyPen—13, Copy Pen (the default); color specified by the ForeColor property
  vbMergePenNot—14, Merge Pen Not; combination of the pen color and the inverse of the display color
  vbMergePen—15, Merge Pen; combination of the pen color and the display color
  vbWhiteness—16, 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 they’ll 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 it’s 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 book’s accompanying CD-ROM.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.