问题
I am attempting to change the selected printer of my PrintDialog through code. I am creating an image that needs to be printed, but the size of the image determines which printer should be used. I have the name of the printer that I want to use but I just can't figure out where to change that value. Any help can be in either VB.NET or C#.
Thanks.
回答1:
You should look for the PrinterName Property. This property resides in the PrinterSettings Class. The PrinterSettings class is also a property of the PrintDialog. This way you can access the PrinterSettings and change the PrinterName-property.
//Example for GETTING the printername
var pd = new PrintDialog();
var settings = pd.PrinterSettings;
var name = settings.PrinterName
//Example for SETTING the printername
var pd = new PrintDialog();
pd.PrinterSettings.PrinterName = "YOUR_PRINTER_NAME";
Hope this helps.
来源:https://stackoverflow.com/questions/15641800/change-printername-in-printdialog-through-code