Академический Документы
Профессиональный Документы
Культура Документы
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
Width
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
Multiple
Examples:
Printer.FontBold = True
Printer.FontItalic = True
Printer.FontSize = 70
Printer.Print This text is boldfaced and italicized.
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
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.