?
Solved

print dialog with an option to map printer

Posted on 2016-09-07
11
Medium Priority
?
65 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 70

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
Quick Cloud Training

Looking for some quick training on the cloud in 2 hours or less? Check out these how-to guides in AWS, Linux, OpenStack, Azure, and more!

 
LVL 70

Accepted Solution

by:
Éric Moreau earned 2000 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
 
LVL 70

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 70

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

719 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