简体   繁体   English

如何在打印对话框中选择打印机进行打印过程

[英]How print dialog box selected printer to printing process

I am trying to print PDF file using Process 我正在尝试使用Process打印PDF文件

PrintDialog pdf = new PrintDialog();
if (pdf.ShowDialog() == DialogResult.OK)
{
  pdf.AllowSelection = true;
  pdf.AllowSomePages = true;
  ProcessStartInfo info = new ProcessStartInfo();
  info.Arguments = pdf.PrinterSettings.PrinterName;
  info.CreateNoWindow = true;
  info.Verb = "print";
  info.FileName = filename;
  //info.WindowStyle = ProcessWindowStyle.Hidden;
  try
  {
    Process p = new Process();
    p.StartInfo = info;
    p.EnableRaisingEvents = true; //Important line of code
    //p.PriorityBoostEnabled = true;
    p.Start();
    p.WaitForExit();
    p.Close();
  }
  catch (Exception ex){}
}
else
{
  MessageBox.Show("Print Canceled");
}
}
catch (Exception ex){}

But this code not take user selected printer for print process. 但是此代码不会将用户选择的打印机用于打印过程。 It print pdf by default printer. 默认情况下,它会打印pdf。 what would be the fault? 怎么了 Thanks. 谢谢。

@RiksonTool, @RiksonTool,

Your code is printing to pdf by default printer as it is reading the settings from control panel of windows. 默认情况下,从Windows的控制面板读取设置时,您的代码将打印为pdf。 This is not a fault, it is a manifestation of the default settings in windows. 这不是故障,它是Windows中默认设置的体现。

Hope it helps 希望能帮助到你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM