ИмяФормы.PrintForm
As the given command fulfills bit-by-bit transfer of the form together with title and the frame on the printer, it does not possess sufficient flexibility. Moreover, the majority of printers possess большей resolution capability, than the computer screen.
The majority of commands of the printer in Visual Basic depend on page orientation. It means that Visual Basic enumerates all deduced characters (actually points) before information transfer on the printer. It allows to control appearance of printed page completely.
The normal method for information transfer on the printer consists in usage of method Print connected to object Printer. For example, as method Print considers page orientation, it is possible to use properties CurrentX and CurrentY for exact positioning of the text and even points on page.
Syntax of a command for an output of the text to the press is very simple:
Printer. Print the text
In the given context it is possible to use characters ";" and ", in the same way, as in forms. The semicolon suppresses automatic passage to the next line, and the comma carries out passage to a new printing zone (the same 14 columns). Functions Tab and Spc work similarly.
To control properties of a font too it is possible in the normal image. For example:
Printer. Font. Name = "Script" ' the index font in the size of 18 points is used
Printer. Font. Size = 18
As well as in forms, changes of a font of the printer do not influence the previous text. All changes are reflected only in again deduced text.
The useful properties and methods for object Printer
If to study context-sensitive help it is possible to be convinced available at object Printer of 40 properties and 12 methods. The majority of them are still unfamiliar to the reader, for example, DrawMode. However their knowledge is very important in respect of operation not only with the printer, but also with forms. The short description of some most often used properties and methods of object Printer more low follows. (See the electronic documentation on those properties and methods which are not described here, and also the documentation on the character constants designating various setting of printers.)
ColorMode. Allows to define printer type - color it or monochrome. Two values of the given property are possible, they are resulted in the table more low.
|
|
|
| vbPRSMMonochrome |
|
| vbPRSMColor |
|
Copies. Installs an amount printed copies.
Height, Width. Return the horizontal and vertical sizes of a paper in the printer installed in Windows. They are measured in твипсах if other unit of measure only is not installed. The given values cannot be changed in program operation; they are intended only for reading. They are used, for example, for check of, whether the user switched to other size of a paper if the deduced information does not find room on a standard sheet 8,5х11 inches. (For such page Visual Basic produces value of width 12 288 твипсов and heights - 15 744 твипсов.)
EndDoc. This method informs Windows on the termination of operation with the document. Its syntax following:
Printer. EndDoc
The given line releases storage from the last pages of the text and sends them in the Manager of Press Windows on the press.
NewPage. The given method completes current page and sends to the printer branch instruction on the following page. Syntax:
Printer. NewPage
Page. This property saves an amount of the printed pages of the current document. The counter begins with 1 and comes to an end after performance of operation EndDoc. It increases by 1 every time at usage of method NewPage, and also in cases when the deduced information does not hold on one page. Normally it
Use at a page header output.
PrintQuality. It is used for printing quality setting if it supports the printer driver. Syntax:
Printer. PrintQuality = value where it is possible to use четьгое встпоенные constants, пепечисленные in the table more low
|
|
|
|
| vbPRPQDraft |
|
The draft press |
| vbPRPQLow |
|
Low resolution |
| vbPRPQMedium |
|
Average resolution |
| vbPRPQHigh |
|
High resolution |
On determination object Printer represents current printer Windows. Dial-up Printers, on the other hand, allows to get access to all installed drivers of printers in system (for example, it can be and the fax driver). The number of the installed printers can be received so:
Printers. Count
Access to a dial-up element is carried out as follows:
Printers {an index},
Where the index means number from 0 to Printers. Count - 1.
For example, the following fragment of the code is used by operator For-Next for check of each printer of system by sign color/monochrome. (After learning of several more commands you can easily add here some lines to suggest the user to pass to the color printer.)
For I = 1 That Printers. Count - 1
If Printers (I).ColorMode = vbPRCMColor Then
MsgBox "At least one printer has a color mode"
End If Next I
Information printing in RichTextBox
Method SelPrint allows to print the current formatted contents of the given control item on the current printer. If thus the user selected the text inside RichTextBox method SelPrint sends on the printer only the selected fragment. If the text is not selected, on the printer all contents RichTextBox are sent. To translate the printer in a ready state (Ready), it is necessary to send at first on it blank line. Further it is necessary to use a context of the device for the current printer. (The device context represents an integer number which Windows uses for object identification.)
Thus, the sample program will look so:
Printer. Print. ""
RichTextBoxl. SelPrint (Printer.hDC)
(Property hDC object Printer defines the identifier of a context of the device. It is used Windows for the special purposes and it is better not to investigate into how it works.)