This class allows you to print documents on printers or save them in a file (PDF, PostScript). This class Printer (gb.form.print) is a new implementation of the class Printer (gb.qt4). Four (margin) properties and the Preview() method have been added.
The class can be created. How to create a new Printer object:
Dim hformPrinter As Printer hformPrinter = New Printer() [ As "EventName" ]
The Printer (gb.form.print) class has the same constants as the Printer (gb.qt4) class, which are described in the 'Printer (gb.qt4) class' section.
The Printer (gb.form.print) class has the same properties as the Printer (gb.qt4) class, which are described in the 'Printer (gb.qt4) class' section.
The new implementation of the Printer (gb.form.print) class has been extended by 4 properties:
Property | Data type | Description |
---|---|---|
Margin.Top | Integer | Return or specification of the top margin in millimetres. |
Margin.Right | Integer | Return or set the right margin in millimetres. |
Margin.Bottom | Integer | Return or set the bottom margin in millimetres. |
Margin.Left | Integer | Return or specification of the left page margin in millimetres. |
Table 23.6.3.2.1 : Additional properties of the Printer (gb.form.print) class
Like the Printer class (gb.qt4), the Printer class (gb.form.print) has these two static properties:
The Printer class (gb.form.print) has the same methods as the Printer class (gb.qt4). However, the 'Preview()' method has been added to the new implementation:
Method | Return type | Description |
---|---|---|
Cancel() | - | Cancels the current print job. |
Configure() | Boolean | Opens the printer configuration dialogue. This method returns TRUE if the user has cancelled the dialogue and FALSE otherwise. |
Print() | - | The print process is started. A local event loop is executed during the process and the method returns when printing is complete. This method returns TRUE if the user has cancelled the print process or if an error has occurred. FALSE is returned if everything was OK. |
Preview() | - | Opens a print preview as a modal form. |
Table 23.6.3.3.1 : Methods of the Printer class (gb.form.print)
The Printer (gb.form.print) class has the same events as the Printer (gb.qt4) class.
Event | Description |
---|---|
Begin() | This event is triggered when the printing process begins. |
End() | This event is triggered when printing is complete. |
Draw() | This event is triggered for each (new) page that needs to be printed. |
Paginate | This event is triggered so that you can paginate your document in the background. If you do not define an event handler, this event is not triggered. You must then define the Count property within the Begin() event handler. Otherwise - if you handle this event - the event handler will be called again and again until you explicitly define the Count property. |
Table 23.6.3.4.1 : Events of the Printer class (gb.form.print)
The following section presents an adaptation of the source code print programme from the Gambas IDE. It uses the margin property for all 4 margins and the print preview. In the preview, you can still make some changes to the design and layout of the print pages and then print the text directly to the selected printer or print it to a PDF file.
Figure 23.6.3.5.1: Print preview
Figure 23.6.3.5.2: Text editor
Notes:
Project