Hi.
I'm migrating from winForm to WPF and I have the following code which works very well:
printDialog = new PrintDialog();
if (DialogResult.OK == printDialog.ShowDialog())
{
try
{
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(PrintImage);
pd.PrinterSettings = printDialog.PrinterSettings;
pd.Print();
}
catch
{
}
}
Now in wpf it is indicated that there is an error in the line:
pd.PrinterSettings = printDialog.PrinterSettings;
So to test if the rest of the code works I commented it and it works very well, but obviously it always prints on the printer that the PC has configured by default.
I tried to investigate in other threads how to solve this problem and the solution is supposedly the following:
PrintDocument pd = new PrintDocument();
PrinterSettings ps = new PrinterSettings();
pd.PrintPage += new PrintPageEventHandler(PrintImage);
printDialog.PrintQueue = new PrintQueue(new PrintServer(),"The exact name of my printer");
pd.Print();
My question is: How can I get the name of the printer? Before winForms I didn't need to do that, I imagine that printDialog took care of that at the moment that the user chose the printer.
Any comments or suggestions are welcome.