
Here is our code:
Public Sub PrintChartOrGrid()
Dim iPrinter As Integer
Dim PrintDlg As PrinterDlg
Dim NewPrinterName As String
Dim objPrinter As Printer
Dim strSetting As String
1
On Error GoTo err_Handler
5
Set PrintDlg = New PrinterDlg
10
' Set the starting information for the dialog box based on the current
' printer settings.
With PrintDlg
.PrinterName = Printer.DeviceName
.DriverName = Printer.DriverName
.Port = Printer.Port
20
' Set the default PaperBin so that a valid value is returned even
' in the Cancel case.
.PaperBin = Printer.PaperBin
' Set the flags for the PrinterDlg object using the same flags as in the
' common dialog control. The structure starts with VBPrinterConstants.
.flags = VBPrinterConstants.cdlPDNoSelection _
Or VBPrinterConstants.cdlPDNoPageNums _
Or VBPrinterConstants.cdlPDReturnDC
Printer.TrackDefault = False
30
' When CancelError is set to True the ShowPrinterDlg will return error
' 32755. You can handle the error to know when the Cancel button was
' clicked. Enable this by uncommenting the lines prefixed with "'**".
.CancelError = True
40
' Add error handling for Cancel.
On Error GoTo err_Printer
45
'Show printer dlg...
If .ShowPrinter(Me.hwnd) Then
'Turn off Error Handling for Cancel.
On Error GoTo err_Handler
50
' Locate the printer that the user selected in the Printers collection.
NewPrinterName = UCase$(.PrinterName)
If Printer.DeviceName <> NewPrinterName Then
For Each objPrinter In Printers
If UCase$(objPrinter.DeviceName) = NewPrinterName Then
Set Printer = objPrinter
End If
Next
End If
60
' Copy user input from the dialog box to the properties of the selected printer.
Printer.Copies = .Copies
Printer.Orientation = .Orientation
Printer.ColorMode = .ColorMode
Printer.Duplex = .Duplex
65
Printer.PaperBin = .PaperBin
Printer.PaperSize = .PaperSize
Printer.PrintQuality = .PrintQuality
70
End If
End With
80
'Print the TCHART!
With Me.TChart1
'Set TCHART printer object to one selected above...
For iPrinter = 0 To .Printer.PrinterCount - 1
If Printer.DeviceName = .Printer.PrinterDescription(iPrinter) Then
.Printer.PrinterIndex = iPrinter
Exit For
90
End If
Next 'iPrinter
100
m_bChartIsPrinting = True
.Printer.MarginLeft = 5
.Printer.MarginRight = 5
.Printer.MarginTop = 5
.Printer.MarginBottom = 5
110
.Printer.PrintChart
DoEvents
120
m_bChartIsPrinting = False
.Environment.InternalRepaint
End With
Me.TChart1.Repaint
DrawAnnotations
Exit Sub
err_Printer:
If Err.Number = 32755 Then
Err.Clear
Exit Sub
End If
err_Handler:
Call HandleError(Erl, ConvertErrToTPCError(Err), "frmRG_CHART:PrintChartOrGrid")
m_bChartIsPrinting = False
End Sub
BTW, we are using the MS VBPrnDlg.DLL control to bypass the anomolies encountered with the normal common dialog control.
Tanks!