How can I open the printer "Preferences" dialog?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?T21lZ2FTcXVhcmVk?=

    #1

    How can I open the printer "Preferences" dialog?

    have customized PageSetup and Print dialogs that emulate the standard
    dialogs. I would like to be able to open the "Printer Preferences" dialog by
    clicking a button (just like can be done on the standard dialogs).

    (On some Print dialogs (such as in Word and Excel) this button is labelled
    "Properties ". And just to avoid being too consistent, it is labelled
    "Options" on the Excel PageSetup dialog.)

    I thought that this would be trivial, but so far I haven't been able to
    figure out how to do this. Does anyone know of an easy way to open this
    "Printer Preferences" dialog box?

    Thanks,
    Randy

  • =?Utf-8?B?T21lZ2FTcXVhcmVk?=

    #2
    RE: How can I open the printer "Preferenc es" dialog?

    For anyone else who may be interested, I finally found the answer here:



    This answer is provided by (and with my thanks to) Bart Mermuys. The
    following snippet shows the essence of the solution.

    Cheers,
    Randy

    Imports System.Drawing. Printing
    Public Class Form1
    Private Const DM_IN_BUFFER As Integer = 8
    Private Const DM_OUT_BUFFER As Integer = 2
    Private Const DM_IN_PROMPT As Integer = 4

    Private Declare Auto Function GlobalLock _
    Lib "kernel32.d ll" (ByVal handle As IntPtr) As IntPtr
    Private Declare Auto Function GlobalUnlock _
    Lib "kernel32.d ll" (ByVal handle As IntPtr) As Integer
    Private Declare Auto Function GlobalFree _
    Lib "kernel32.d ll" (ByVal handle As IntPtr) As IntPtr
    Private Declare Auto Function DocumentPropert ies _
    Lib "winspool.d rv" (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

    Sub ShowPrinterProp erties(ByVal Settings As PrinterSettings )
    ' PrinterSettings +PageSettings -hDEVMODE
    Dim hDevMode As IntPtr
    hDevMode = Settings.GetHde vmode(Settings. DefaultPageSett ings)
    ' Show Dialog ( [In,Out] pDEVMODE )
    Dim pDevMode As IntPtr = GlobalLock(hDev Mode)
    DocumentPropert ies(Me.Handle, IntPtr.Zero, _
    Settings.Printe rName, pDevMode, pDevMode, _
    DM_OUT_BUFFER Or DM_IN_BUFFER Or DM_IN_PROMPT)
    GlobalUnlock(hD evMode)
    ' hDEVMODE -PrinterSettings +PageSettings
    Settings.SetHde vmode(hDevMode)
    Settings.Defaul tPageSettings.S etHdevmode(hDev Mode)
    ' cleanup
    GlobalFree(hDev Mode)
    End Sub

    Private Sub Button1_Click(B yVal sender As System.Object, _
    ByVal e As System.EventArg s) _
    Handles Button1.Click
    If (Me.PrintDocume nt1.PrinterSett ings.IsValid) Then
    Me.ShowPrinterP roperties(Me.Pr intDocument1.Pr interSettings)
    Else
    MsgBox("Invalid Printer Name!", MsgBoxStyle.Inf ormation)
    End If
    End Sub

    End Class

    Comment

    Working...