Home > BSPrinter documentation > Reference

IPrinterEx object


Global object that can be used instead of a PrintPreview control, for example in class modules.

This object uses this interface, which is returned by the class Global from its property PrintPreview.
It has the same properties and methods of the PrintPreview control, but it is a global object and it doesn't require a form to stay on, thus allowing to print from class modules.
Being a global object it does not require to be instantiated.

The usage for most of the properties and actions is the same as for a PrintPreview control.
But it has another way to handle events and to call the printing routine.
To handle, events see the property Events which returns an PrinterExEvents object.

There are two ways of calling the printing routine:

First option: To use the PrepareReport event of the PrinterExEvents object returned by the Events property.

Sample usage in a class module:

Private WithEvents mPrinterExEvents As PrinterExEvents

Private Sub Class_Initialize()
    Set mPrinterExEvents = PrintPreview.Events
End Sub

Public Sub PrintPreviewMyReport() ' This is the method that will be called to show the print preview dialog with the report
    PrintPreview.ShowPreview
End Sub

Private Sub mPrinterExEvents_PrepareReport(Cancel As Boolean)
    MyPrintingProcedure
End Sub

Private Sub MyPrintingProcedure()
    Printer.Print "Hello Word"
    ' continue with the printing code
End Sub


Second option: To set the printing procedure using the SetPrintingProcedure method.

Sample usage in a class module:
Private Sub Class_Initialize()
    PrintPreview.SetPrintingProcedure Me, "MyPrintingProcedure"
End Sub

Public Sub PrintPreviewMyReport() ' This is the method that will be called to show the print preview dialog with the report
    PrintPreview.ShowPreview
End Sub

Public Sub MyPrintingProcedure()
    Printer.Print "Hello Word"
    ' continue with the printing code
End Sub


Note that the printing routine must be declared as Public with this approach.

Also do not forget to add the code necessary to replace the Printer object to a bas module:

Public Property Get Printer() As Printer
    Set Printer = BSPrinter.PrinterReplacement
End Property

Public Property Set Printer(nPrinter As Printer)
    Set BSPrinter.PrinterReplacement = nPrinter
End Property


  • Properties
  • Methods

  • Properties

    AllowUserChangeMargins
    AllowUserChangeOrientation
    AllowUserChangePageNumbers
    AllowUserChangePaperSize
    AllowUserChangePrinter
    AllowUserChangeScale
    AuxiliaryButtonToolTipText
    AuxiliaryButtonVisible
    BottomMargin
    BottomMarginEffective
    BottomNonPrintableArea
    Canceled
    Collate
    ColorSupport
    CurrentPageInPreview
    Events
    Flags
    FontWidth
    FormatButtonVisible
    FromPage
    GDIPlusGraphics
    GridReportStyles
    HandleMargins
    LeftMargin
    LeftNonPrintableArea
    LetPrintExceedMargin
    MarginsButtonVisible
    MarginUnits
    MarginUnitsForUser
    MaxScalePercent
    MenuButtonIcon
    MenuButtonVisible
    MinBottomMargin
    MinLeftMargin
    MinRightMargin
    MinScalePercent
    MinTopMargin
    PageCount
    PageNumbersColor
    PageNumbersFont
    PageNumbersFormat
    PageNumbersPosition
    PageNumbersPositionFlags
    PageSetupButtonVisible
    PageView
    PageViewNormalSizeButtonVisible
    PreviewDialogCaption
    PreviewPagesAccuracy
    Printed
    PrintPageNumbers
    QuickPrintButtonVisible
    RememberUserPreferences
    ReportID
    ReportName
    RightMargin
    RightNonPrintableArea
    RightToLeftControl
    ScalePercent
    ShowBottomToolbar
    ShowFirstPageNumber
    ShowMargins
    ShowSketch
    SomethingPrintedOnPage
    SomethingPrintedOnReport
    StartingPageNumber
    ToolbarButtonPicture
    ToolbarIconsSize
    ToPage
    TopMargin
    TopMarginEffective
    TopNonPrintableArea
    UIButtonStyle
    UIFontName
    UILanguage
    UseAltScaleIcons

    Methods

    AddWatermark
    ClearPage
    DeleteAllUserPreferences
    DeleteUserPreferences
    GetCurrentGridReportStyle
    GetDocFirstPageIndex
    GetDocLastPageIndex
    GetDocPageCount
    GetFooterPos
    GetHeaderPos
    GetLastDeviceName
    GetPageNumber
    GetPageNumberPos
    GoToPage
    PrintDirect
    PrinterExists
    PrintEx
    PrintForm
    PrintGrid
    PrintRichTextBox
    PrintWindow
    ReleasePrinterObject
    RemoveAllWatermarks
    RemovePage
    RemoveWatermark
    SaveToFile
    SelectPrinter
    SetFooter
    SetHeader
    SetPrintingProcedure
    ShowFormatOptions
    ShowPageNumbersOptions
    ShowPageSetup
    ShowPreview
    ShowPrinter
    ShowSaveToFile
    TextHeightEx
    TextWidthEx