Solved

print dialog with an option to map printer

Posted on 2016-09-07
11
41 Views
Last Modified: 2016-09-12
The code below does not give a choice to add printer or map it.
Any suggestions?
 Private Sub PrintExcel()
        Dim PrintDialog1 As New PrintDialog()
        Dim clsFrmain As New ClsFrmMainLoad
        Dim result As DialogResult = PrintDialog1.ShowDialog()
        If (result = DialogResult.OK) Then
            Dim strFile As String = StrExcelLocation
            Dim objProcess As New System.Diagnostics.ProcessStartInfo
            Dim strPrnterName As String = StrPrinterName
            With objProcess
                strFile = clsFrmain.ReturnPrintFilePath()
                .FileName = strFile
                .WindowStyle = ProcessWindowStyle.Hidden
                .Verb = "printTo"
                .Arguments = PrintDialog1.PrinterSettings.PrinterName
                .CreateNoWindow = True
                .UseShellExecute = True
            End With
            Try
                System.Diagnostics.Process.Start(objProcess)
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End If
    End Sub

Open in new window

0
Comment
Question by:RIAS
  • 5
  • 4
  • 2
11 Comments
 
LVL 25

Expert Comment

by:SStory
ID: 41787850
Something like this???

Dim settings = PrintDialog1.PrinterSettings
Then manipulate settings class??

The info on that class is here:
https://msdn.microsoft.com/en-us/library/system.drawing.printing.printersettings.aspx

If not, what do you mean by "map printer"?
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 41787868
The PrintDialog is a very generic dialog (the same used by Windows) and has no option to allow the user to map a new printer.

You can surely use the Process component to allow the user to open the Devices and Printers by sending this command:
explorer shell:::{A8A91A66-3A7D-4424-8D24-04E180695C7A}

Open in new window

0
 

Author Comment

by:RIAS
ID: 41787924
how to embed in the code
0
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 41787955
use this:
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Process.Start("explorer.exe", "shell:::{A8A91A66-3A7D-4424-8D24-04E180695C7A}")
    End Sub

Open in new window

0
 

Author Comment

by:RIAS
ID: 41788403
Eric, It did not bring the dialog box
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 69

Expert Comment

by:Éric Moreau
ID: 41788412
that last process.start should show the "Devices and Printers" dialog from which you can add a printer. Don't you see it?
0
 

Author Comment

by:RIAS
ID: 41789096
Éric Moreau,
Thanks it did open the dialog but how do I  code to have  the printer selected  ?

[code]Private Sub PrintExcel()
        Dim PrintDialog1 As New PrintDialog()
        Dim clsFrmain As New ClsFrmMainLoad
        Dim result As DialogResult = PrintDialog1.ShowDialog()
        If (result = DialogResult.OK) Then
            Dim strFile As String = StrExcelLocation
            Dim objProcess As New System.Diagnostics.ProcessStartInfo
            Dim strPrnterName As String = StrPrinterName
            With objProcess
                strFile = clsFrmain.ReturnPrintFilePath()
                .FileName = strFile
                .WindowStyle = ProcessWindowStyle.Hidden
                .Verb = "printTo"
                .Arguments = PrintDialog1.PrinterSettings.PrinterName
                .CreateNoWindow = True
                .UseShellExecute = True
            End With
            Try
                System.Diagnostics.Process.Start(objProcess)
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End If
    End Sub[/code]
0
 

Author Comment

by:RIAS
ID: 41789180
Private Sub PrintExcel()
        Dim PrintDialog1 As New PrintDialog()
        Dim clsFrmain As New ClsFrmMainLoad
        Dim result As DialogResult = PrintDialog1.ShowDialog()
        If (result = DialogResult.OK) Then
            Dim strFile As String = StrExcelLocation
            Dim objProcess As New System.Diagnostics.ProcessStartInfo
            Dim strPrnterName As String = StrPrinterName
            With objProcess
                strFile = clsFrmain.ReturnPrintFilePath()
                .FileName = strFile
                .WindowStyle = ProcessWindowStyle.Hidden
                .Verb = "printTo"
                .Arguments = PrintDialog1.PrinterSettings.PrinterName
                .CreateNoWindow = True
                .UseShellExecute = True
            End With
            Try
                System.Diagnostics.Process.Start(objProcess)
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End If
    End Sub

Open in new window

0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 41789265
those are 2 very different dialogs that are offering very different features. One is to add/remove printers and set default while the second dialog is to pick a printer. Microsoft did not create a single dialog combining both. Unless you set a default printer in the Devices and Printers dialog, there is no way to retrieve the selected item.
0
 
LVL 25

Expert Comment

by:SStory
ID: 41789402
Apart from creating your own dialog, I am not sure.  Printer information for the current user is in the registry key:
HKEY_CURRENT_USER\Printers

Default printer:
HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows

Per this:
https://support.microsoft.com/en-us/kb/102966

It would probably take some work to do. If I did it I'd model it as closely to the expected dialog as possible to avoid inconsistent behavior for the user.
0
 

Author Closing Comment

by:RIAS
ID: 41793843
Thanks.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now