![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
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 outputlist argument can contain the following parts, all of which are optional:
If outputlist has more than one item, the items can be separated either with a space or a semicolon. After the Print method is executed, the default ensures that the output of the next Print method is placed on the next line. You can modify the default by placing one of the following arguments at the end of outputlist :
Most of the fonts you will use in Visual Basic have proportionally spaced characters in which a wide letter (such as a W) occupies more horizontal space than a narrow letter (such as an i). Therefore, no correlation exists between the number of characters printed and the amount of horizontal space used. You can avoid this problem by using a fixed-pitch font, such as Courier, in which all characters occupy the same amount of horizontal space. Proportional fonts are nicer looking, however, so youll usually want to use them. When using proportional fonts, how do you know when the output of the Print method is going to reach the right edge of the object being printed on, making it necessary to start a new line? Remember that the Print method outputs text at the objects current position. If we know the width of the next chunk of text to be printed, we can do the following (as expressed in pseudocode): If ((current X position) + (Width of text)) > (width of object) then it won't fit; advance to beginning of next line else it will fit; output on current line end if You can obtain the width of a unit of text using the TextWidth method. All objects to which the Print method applies support this method. If you pass a string as the argument, TextWidth returns the width that the text would occupy if printed or displayed, expressed in the objects current horizontal coordinate units. The value takes into account the objects current Font property setting. How do you advance a line? The best way is to manipulate the objects CurrentY property directly. First, obtain the height of a line of text using the TextHeight method. TextHeight works just as TextWidth, returning the height (in object units) of the specified text in the current font. The value returned by TextHeight includes the leading, or space between lines of text. Assume that the variable S$ contains the next unit of text to be printed on Form1. Assume also that the variables LMargin and RMargin contain the desired left and right margins, respectively. The following code will wrap to the next line if needed: If ((Form1.CurrentX + Form1.TextWidth(S$)) > (Form1.ScaleWidth - RMargin) Then Form1.CurrentX = LMargin Form1.CurrentY = Form1.CurrentY + Form1.TextHeight(S$) End If Form1.Print S$; The Line And Shape ControlsIf you need to draw permanent lines and shapes on a form, the Line and Shape controls are your best bet. By permanent, I mean that you do not need to modify the drawn objects during program execution. What you draw during program design is exactly what will be displayed during program execution. For this reason, they are most often used for decorative purposes, such as providing interesting borders for controls or dividing a form into sections. Neither of these controls has any associated events. Figure 12.13 shows a Picture Box with a border created with several Shape controls, each slightly larger than the next. To use the Line or Shape control, simply place it on your form as you would any other control. You can choose from the following properties to change the Line controls appearance:
The Shape control has the previous four properties, plus some additional ones:
Printing With The Printer ObjectSo far, we have limited ourselves to displaying graphics and text on screen. Often, youll need to send graphics and text to the printer as well. Visual Basic makes this easy with the Printer object. The Printer object has the same properties and methods as the Form and Picture Box objects (those properties and methods related to graphics, at least). Therefore, if you want to print text to the printer, write: Printer.Print message The same goes for the Line, Circle, and Pset methods. Just like the Form or Picture Box objects, the Printer object has a current position defined by the CurrentX and CurrentY properties, the ability to report the width and height of text with the TextHeight and TextWidth methods, the ability to act as the destination (but not the source) for the PrintPicture method, and so on. For the most part, you can do the same things with the Printer object or a Form object, depending on whether you want the output displayed on the screen or sent to the printer.
|
![]() |
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. |