Вы находитесь на странице: 1из 4

Lesson XIX:

The Printer Object

Objectives
To be able to print texts and graphics using the Print object
To be able to manipulate the printer object to print according to user preferences
Notes
Visual Basic applications send all printed output to a special VB object called the Printer object.
The Printer Object supports several property and methods that help you customize how the print
out will look like on paper.
The following table lists the Printers properties.
Property
ColorMode
Copies
CurrentX
DrawWidth
FillColor
FillStyle
FontBold
FontItalic
FontName
FontSize
FontStrikeThr
u
FontUndeline
ForeColor
Height
Orientation
Page
PaperBin

PaperSize

PrintQuality

ScaleMode

Description
1: vbPRCMonochrome, outputs prints in monochrome
2: vbPRCMColor, outputs prints in color
Specifies the number of copies to print.
Holds the vertical print row, from the upper-left corner of the
page, measured either in twips or the scale defined by the
ScaleMode property.
Specifies the width of lines drawn, from 1 (default) to 32767
pixels.
Specifies the color of printed shapes.
Contains the pattern of printed shapes.
Boolean. Determines whether subsequent printed output
will be boldfaced or not.
Boolean: Determines whether subsequent printed output will
be italicized or not.
Holds the name of the current font being used for output.
Holds the size, in points, of the current font.
Boolean. Determines whether subsequent output will be
printed with a strikethrough line.
Boolean. Determines whether subsequent output will be
underlined.
Specifies the foreground color of printed text and graphics.
Holds the height, in twips, of the current printed page.
1: vbPRORPortrait, outputs prints in portrait mode.
2: vbPRORLandscape, outputs prints in landscape mode
Contains the page number currently being printed and
updated automatically by Visual Basic.
Specifies which paper bin the print job will use. Commonlyused values are:
1: vbPRBNUpper, Use paper from the upper bin.
2: vbPRBNLower, Use paper from the lower bin.
4: vbPRBNManual, Wait for manual insertion of each sheet of
paper.
5: vbPRBNEnvelope, Use envelopes from the envelope
feeder.
6: vbPRBNEnvManual, Use envelopes from the envelope
feeder, but wait for manual insertion.
8: vbPRBNTractor, Use paper fed from the tractor feeder.
Specifies the size of paper the print job will use. Commonlyused values:
1: vbPRPSLetter, Letter, 8 1/2 x 11 in.
5: vbPRPSLegal, Legal, 8 1/2 x 14 in.
9: vbPRPSA4, A4, 210 x 297 mm
256: vbPRPSUser, User-defined
Determines how fine the print quality will appear.
1: vbPRPQDraft, least quality, but prints quickly
2: vbPRPQLow, low-resolution mode
3: vbPRPQMedium, medium-resolution mode
4: vbPRPQHigh, slowest quality
Sets the unit of measurement for all subsequent printed

output that appears.


1: vbTwips, Measured in twips (default)
2: vbPixels, Measured in pixels
5: vbInches, Measured in inches
6, vbMillimeters, Measured in millimeters
7: vbCentimeters, Measured in centimeters
Holds the size of the page width (in twips).

Width

The following are the methods of the Print object.


Method
Circle
EndDoc

Description
Draws a circle or an arc.
Releases the current document to the print spooler for
output.
Immediately terminates the output and deletes the current
print job from the print spooler.
Draws lines and boxes on the page.
Sends a page break to the printed output so that subsequent
output appears on the next page.
Prints numeric and text data.

KillDoc
Line
NewPage
Print

IN FOCUS: THE PRINT METHOD


The Print method handles almost all the printing jobs. With this method, you can print literals,
variables, constants, and expressions. The syntax of the Print method is as follows:
Printer.Print <expression>
Below are examples on how to use the Print method:
Printing Literals
Examples:
Printer.Print 1
Printer.Print 12.5
Printer.Print Computer Science
Printer.Print
Prints a blank line
Note: Print method prints a new line after printing the
expressions.
Printing Variables
Examples:
Fname = Jennifer
Age = 24
Printer.Print Fname
Printer.Print Age
Printing Expressions
Examples:
Printer.Print 45 + ( 4 * 3)
Printer.Print RawScore/TotalScore * 100
Printer.Print Name: & Fname & Lname
Printing
Values

Multiple

Printer.Print Score: ; intScore; Letter Grade; strLGrade


The Semi-colon keeps the printers print head at the
end of the message for subsequent output.
Printer.Print strName, strCourse, strYear
The comma is still used to print values in the same line
but at specific print zone. A print zone occurs every 14
columns on the page.

Utilizing the Fonts

Examples:
Printer.FontBold = True
Printer.FontItalic = True
Printer.FontSize = 70
Printer.Print This text is boldfaced and italicized.

Spacing with Spc()


and
Tab()

Examples:
Printer.Print Fname; Spc(10); Lname
The above example prints a 10 spaces between the
value of Fname and the value of Lname.
Printer.Print Tab(5), Total

The string Total is printed in the 5th column


Example 1:
Printer.Print First Page
Printer.NewPage
Printer.Print Second Page
Printer.EndDoc

Lesson in Action
Create the following Form.

When the user clicks on the Print button, the following should be the output:
Name:
Racines, Mark
Age:
4
Level/Section: Nursery Blue
Write the following procedure:
Private Sub Command1_Click()
Printer.FontName = Arial
Printer.Print Name: ;
Printer.FontBold = True
Printer.FontUndeline = True
Printer.Print Tab(2); txtLName.Text & , & txtFName.Text
Printer.FontBold = False
Printer.FontUndeline = False
Printer.Print Age:; Tab(2); txtAge.Text
Printer.Print Level/Section:; Tab(1); cboLevel.Text & - & cboSection.Text
Printer.EndDoc
End Sub

On your Own
Instructions: Create a simple text editor. The Editors interface is as follows:

When the Print button is clicked, the following dialog box is displayed:

For the Paper Size ListBox (DropDown ListBox), include three items: Letter, 8 1/2 x 11 in., Legal,
8 1/2 x 14 in., and A4, 210 x 297 mm. The Color ListBox (DropDown ListBox) contains four
colors: Black, Blue, Red, and Green. Enable this ListBox only when Color Mode (see the Color
Mode Frame above) is set to Color. Color refers to the color of the text when printed.
When the Print button is pressed, print the text in entered in the previous Form. Apply print the
settings set by the user. Unload the Form and load the main Form. Clicking Cancel also invokes
back the main Form.

Вам также может понравиться