Change printername in PrintDialog through code

折月煮酒 提交于 2019-12-07 21:07:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!