Solved

VB.NET - Change Windows Printer Settings...

Posted on 2009-05-13
3
1,041 Views
Last Modified: 2012-08-13
I am trying to figure out how to show the user a list of their installed printers to choose from.  Then, based on the printer they select, show then the available paper sizes for that printer.  And then, for the printer they selected, change some of their windows printer settings for that printer.  Specifically:  Paper Size and print Landscape instead of Portrait.

So what I'm needing to figure out how to do:

1.  Show the user a list of their installed printers via combobox or listbox
2.  Based on their selection, show the user the available paper sizes for that printer via combobox or listbox.
3.  Change the default paper size and orientation of the chosen printer.  (Same as you would do manually by going to Printers and Faxes, right-clicking on the printer, and choosing Properties.)
0
Comment
Question by:LittleOleMeDesigns
[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
3 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24386569
0
 
LVL 15

Accepted Solution

by:
oobayly earned 500 total points
ID: 24386782
You can use the PrinterSettings class in System.Drawing.Printing.

Assuming you've got a form called Form1 with 2 ComboBoxes comboPrinters & comboPaperSizes
Private settings As New PrinterSettings()
Private page As PageSettings
 
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Form1.Load
    '' Populate a combobox with all the printer names
    comboPrinters.BeginUpdate()
    comboPrinters.Items.Clear()
    For Each name As String In PrinterSettings.InstalledPrinters
        comboPrinters.Items.Add(name)
    Next
    comboPrinters.EndUpdate()
    comboPrinters.SelectedItem = settings.PrinterName
End Sub
 
Private Sub comboPaperSizes_SelectedValueChanged(ByVal sender As Object, ByVal e As EventArgs) Handles comboPaperSizes.SelectedValueChanged
    page = New PageSettings(settings)
    page.PaperSize = DirectCast(comboPaperSizes.SelectedValue, PaperSize)
End Sub
 
Private Sub comboPrinters_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles comboPrinters.SelectedIndexChanged
    '' Populate a combox with paper sizes 
    settings.PrinterName = DirectCast(comboPrinters.SelectedItem, String)
    Dim sizes As New BindingList(Of PaperSize)()
    For Each size As PaperSize In settings.PaperSizes
        sizes.Add(size)
    Next
    comboPaperSizes.DisplayMember = "PaperName"
    comboPaperSizes.DataSource = sizes
End Sub

Open in new window

0
 
LVL 4

Author Closing Comment

by:LittleOleMeDesigns
ID: 31618525
Thank-You for the excellent example!
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

If your system is showing symptoms of browser hijacks or 'google search redirects' check out my other article (http://rdsrc.us/u3GP7A) first and run the tool TDSSKiller (http://rdsrc.us/GDBBs4) to get rid of the infection. Once done, and if the …
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

734 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