【问题标题】:Printing problem in C# windows app - Always prints to default printerC# windows 应用程序中的打印问题 - 始终打印到默认打印机
【发布时间】:2010-02-23 20:19:33
【问题描述】:

我有以下代码来弹出一个打印机对话框,但无论我选择什么打印机,它总是打印到默认打印机。

如何分配用户选择的打印机? (从对话窗口)

PrintDialog pdlg = new PrintDialog();

// Show the PrintDialog
if (pdlg.ShowDialog() == DialogResult.OK)
{
   PrintDocument pd = new PrintDocument();
   pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);

   // Associate PrintDocument object with the PrintDialog
   pdlg.Document = pd;

   // Print with the new PrinterSettings
   pd.Print();
}

【问题讨论】:

    标签: c# .net winforms printing


    【解决方案1】:

    您需要在调用 ShowDialog() 之前将 PrintDocument 分配给 PrintDialog。

    【讨论】:

      【解决方案2】:

      我认为您需要使用 PrintDialog 实例中的 PrinterSettings 属性,并在您创建的 PrintDocument 实例中设置适当的值。

      换句话说:

      pd.PrinterSettings = pdlg.PrinterSettings;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多