Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

print dialog with an option to map printer

Posted on 2016-09-07
11
Medium Priority
?
67 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 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

876 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