Solved

print dialog with an option to map printer

Posted on 2016-09-07
11
60 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
LVL 70

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
 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

705 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