dimanche 4 mai 2014

.net - changement printername dans PrintDialog code - Stack Overflow


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.




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.



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.



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.


0 commentaires:

Enregistrer un commentaire