Solved

How can I open the printer "Preferences" dialog?

Posted on 2008-10-31
5
315 Views
Last Modified: 2008-11-08
Hello, Experts,

I 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
0
Comment
Question by:omegaomega
  • 3
  • 2
5 Comments
 
LVL 6

Expert Comment

by:RishadanPort
ID: 22853162
Have you tried using the PrintDialog Class?
0
 
LVL 6

Expert Comment

by:RishadanPort
ID: 22853203
Why can't you just do this:

            System.Windows.Forms.PrintDialog dialog = new System.Windows.Forms.PrintDialog();
            dialog.ShowDialog();   <-- in here the user can navigate to the advanced settings.
0
 
LVL 12

Author Comment

by:omegaomega
ID: 22853500
Hello, RishadanPort,

I am using a custom PrintDialog form.  I want to emulate the functionality of the "Preferences" button on the standard PrintDialog form.

Cheers,
Randy
0
 
LVL 12

Author Comment

by:omegaomega
ID: 22872225
For anyone else who may be interested, I finally found the answer here:

http://bytes.com/forum/thread389569.html

This answer is provided by (and with my thanks to)  Bart Mermuys.  The attached 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.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
 
    Sub OpenPrinterPropertiesDialog(ByVal Settings As PrinterSettings)
        ' PrinterSettings+PageSettings -> hDEVMODE
        Dim hDevMode As IntPtr
        hDevMode = Settings.GetHdevmode(Settings.DefaultPageSettings)
        ' Show Dialog ( [In,Out] pDEVMODE )
        Dim pDevMode As IntPtr = GlobalLock(hDevMode)
        DocumentProperties(Me.Handle, IntPtr.Zero, _
                Settings.PrinterName, pDevMode, pDevMode, _
                DM_OUT_BUFFER Or DM_IN_BUFFER Or DM_IN_PROMPT)
        GlobalUnlock(hDevMode)
        ' hDEVMODE -> PrinterSettings+PageSettings
        Settings.SetHdevmode(hDevMode)
        Settings.DefaultPageSettings.SetHdevmode(hDevMode)
        ' cleanup
        GlobalFree(hDevMode)
    End Sub
 
    Private Sub Button1_Click(ByVal sender As System.Object, _
                              ByVal e As System.EventArgs) _
                                        Handles Button1.Click
        If (Me.PrintDocument1.PrinterSettings.IsValid) Then
            Me.ShowPrinterProperties(Me.PrintDocument1.PrinterSettings)
        Else
            MsgBox("Invalid Printer Name!", MsgBoxStyle.Information)
        End If
    End Sub
 
End Class

Open in new window

0
 
LVL 12

Accepted Solution

by:
omegaomega earned 0 total points
ID: 22872276
Well, that is not quite it.  I seem to have slipped up with my copy and paste.  The name of the Sub should be changed from "OpenPrinterPropertiesDialog" to "ShowPrinterProperties" to correspond with what is called in the Button1 Click event.

Cheers,
Randy
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Firing an ASP.NET event on selection of a JQuery datepicker 4 31
Visual Studios 1 77
get combo value in class 5 14
VB.Net - String Manipulation Scenario 2 26
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question