Solved

print dialog with an option to map printer

Posted on 2016-09-07
11
38 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

19 Experts available now in Live!

Get 1:1 Help Now