![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!
The size of the point is controlled by the objects DrawWidth property. If DrawWidth is 1, then the point is a single pixel. For larger values of DrawWidth, the point is centered on the specified coordinates. To erase a single pixel with the Pset method, draw a point using the objects BackColor property setting as the color argument. You can use Pset to implement a simple drawing program with only a few lines of code, as shown in Listing 12.11. We declare a type Boolean variable that will serve as the drawing flag. This flag is set to True when the user presses the mouse button, and cleared (that is, set equal to False) when the user releases the mouse button. Then, in the MouseMove event procedure, we test this flag; if it is True, use Pset to draw a single point at the mouse location. The program is extremely basic, and if you try it, youll see that the drawing cannot keep up with rapid mouse movements. Listing 12.11 Code in DRAWING.FRM. Option Explicit Dim Drawing as Boolean Private Sub Form_MouseDown(Button As Integer, Shift As Integer, _ X As Single, Y As Single) Drawing = True End Sub Private Sub Form_MouseMove(Button As Integer, Shift As Integer, _ X As Single, Y As Single) If Drawing Then PSet (X, Y) End Sub Private Sub Form_MouseUp(Button As Integer, Shift As Integer, _ X As Single, Y As Single) Drawing = False End Sub Other Drawing ConsiderationsIn this section, I will explain some additional properties and keywords that are relevant when drawing graphics objects. Using Relative Coordinates I mentioned earlier that all objects on which graphics can be drawn have a current position defined by its CurrentX and CurrentY properties. All drawing methods (including the Print method, covered in the next section) update the current positionthat is, after the method is executed, the current position points to the location where the drawing ended. In my explanations of the drawing methods, I provided the syntax that uses absolute coordinatesthose that do not reference the current positionto specify where the drawing is to take place. You can also specify drawing coordinates that are based on the current position. For the Line method, you simply omit the first set of coordinates. For example, the statement object.Line -(X,Y) draws a line from the current position to coordinates X,Y. You can also use the Step keyword with either or both of the starting and ending coordinates to specify that the current position be treated as the origin. Here are two examples: object.Line Step(10, 10)-Step(100, 100) object.Line Step(50, 50)-(100, 100) The first statement draws a line that begins 10 units below and 10 units to the right of the current position, ending 100 points below and 100 points to the right of the current position. The second statement draws a line that begins 50 units below and 50 units to the right of the current position, ending 100 points below and 100 points to the right of the objects origin. To use relative coordinates with the Circle method, include the Step keyword before the coordinates. The statement object.Circle Step (0,0), 250 draws a circle centered on the current position. Step can be used with Pset also. The following loop will print a row of 10 dots, starting at the current position, with each dot 10 units below the previous dot: For I = 1 to 10 Form1.Pset Step (0, 10) Next I Without the Step keyword, this loop would print all 10 dots at the same location10 units below the forms origin. Remember that an objects current position is defined by its CurrentX and CurrentY properties. You can set these properties directly to change the current position. The current position can be outside the visible area of the object, and graphical objects can be drawn there, but of course, they wont be visible. The DrawStyle And DrawMode Properties The DrawStyle property affects objects drawn with the Line and Circle methods. It controls whether the line drawn (as a line, border of a rectangle, or edge of a circle) is solid or a combination of dots and dashes. The default is a solid line. All drawing operations on an object (including the Print method) are affected by the objects DrawMode property. DrawMode governs the interaction between the drawn object and the background of the object. Of the 16 different DrawMode settings, most are dedicated to specialized graphics effects. The default setting, Copy Pen (value = 13), does not produce any special effects, but simply draws the graphical object over the background in the specified color. The other 15 settings create various kinds of logical combinations between the background color and the drawing color. I will explain only the most useful one, Invert. You can explore the remaining settings in the Visual Basic Help system. Setting DrawMode to Invert (value = 6) causes the background color to be inverted where the graphical object is drawn. The specified color of the drawn object is ignored. The value of the Invert setting is twofold. First, the drawn object is guaranteed to be visible no matter what the background, because the existing colors are inverted. Secondly, you can erase an object drawn in Invert mode simply by drawing it again at the same location: The pixels are re-inverted to their original values, so the object, in effect, disappears.
Displaying TextTo display text on a Form, Picture Box, or Printer object, you need to use the Print method. The output is created using the font specified by the objects Font property. The output is placed at the location specified by the objects current graphics location (CurrentX and CurrentY properties). You can also use the Print method with the Debug object to display text in Visual Basics Debug window while a program is executing in the Visual Basic development environment (font and current position are meaningless for the Debug object). The Print methods syntax is object.Print outputlist where the arguments are as follows:
|
![]() |
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. Read EarthWeb's privacy statement. |