Posted 7 August 2020, 3:28 pm EST
Hello,
we are trying to implement a custom report dialog in order to bypass an issue we were having with slowness when loading network printers we encountered with the default form. As a part of this we are using the following snippet to open the printer settings page and load the results into the reports printer settings.
Private Declare Auto Function GlobalLock Lib "kernel32.dll" _
(ByVal handle As IntPtr) As IntPtr
Private Declare Auto Function GlobalUnlock Lib "kernel32.dll" _
(ByVal handle As IntPtr) As Integer
Private Declare Auto Function GlobalFree Lib "kernel32.dll" _
(ByVal handle As IntPtr) As IntPtr
Private Declare Auto Function DocumentProperties Lib "winspool.drv" _
(ByVal hWnd As IntPtr, ByVal hPrinter As IntPtr, _
ByVal pDeviceName As String, ByVal pDevModeOutput As IntPtr, _
ByVal pDevModeInput As IntPtr, ByVal fMode As Int32) As Integer
Private Sub ButtonProperties_Click(sender As Object, e As EventArgs) Handles ButtonProperties.Click
' only change PrinterName when it is required, NOT each time the userpresses
' the button, setting a printername resets some of the settings
If (comboBoxPrinters.SelectedIndex <> -1) Then
If (ImagePrintDocument.PrinterSettings.PrinterName <> comboBoxPrinters.Text) Then
Me.ImagePrintDocument.PrinterSettings.PrinterName = comboBoxPrinters.Text
End If
If ImagePrintDocument.PrinterSettings.IsValid Then
Me.OpenPrinterPropertiesDialog(_ImagePrintDocument.PrinterSettings)
Else
MsgBox("Invalid printersettings", MsgBoxStyle.Information)
End If
Else
MsgBox("Choose a printer", MsgBoxStyle.Information)
End If
End Sub
Sub OpenPrinterPropertiesDialog(ByRef Settings As PrinterSettings)
' PrinterSettings+PageSettings -> hDEVMODE
Dim hDevMode As IntPtr = _
Settings.GetHdevmode(Settings.DefaultPageSettings)
' Show Dialog ( [In,Out] pDEVMODE )
Dim pDevMode As IntPtr = GlobalLock(hDevMode)
DocumentProperties(Me.Handle, IntPtr.Zero, _
Settings.PrinterName, pDevMode, pDevMode, 14)
GlobalUnlock(hDevMode)
' hDEVMODE -> PrinterSettings+PageSettings
Settings.SetHdevmode(hDevMode)
Settings.DefaultPageSettings.SetHdevmode(hDevMode)
' cleanup
GlobalFree(hDevMode)
_report.Document.Printer.PrinterSettings = Settings.Clone()
However, it seems that by doing this we are not able to correctly set all of the settings to print in the desired way. For example, the _report.Document.PrintOptions.PagesPerSheet appears to get set correctly, but the _report.Document.PrintOptions.PageScaling does not get set to the correct value to print multiple pages per sheet.
I was wondering if there were any additional/alternate steps that would fix the issue, or failing that if you could provide a list of properties that would need to be set manually.