【问题标题】:Cannot show print dialog on the top of asp.net web control无法在 asp.net web 控件顶部显示打印对话框
【发布时间】:2014-04-07 19:14:36
【问题描述】:

我目前在 ASP.net 中的自定义控件上使用 System.Windows.Forms.PrintDialog,因为我想显示打印对话框并将其 PrinterSettings 分配给 ReportPrintDocument.PrinterSettings 在我单击对话框上的确定按钮后。 这是我的代码:

using (PrintDialog printDialog = new PrintDialog())
                {
                   if (printDialog.ShowDialog() == DialogResult.OK)
                    {
                        ReportPrintDocument rp = new ReportPrintDocument(rvPermit.ServerReport);
                        rp.PrinterSettings = printDialog.PrinterSettings;
                        rp.Print();
                    }
                }

我的问题是打印对话框总是显示在网络浏览器后面,我不知道它是否显示,直到我最小化网络浏览器。

您知道如何在 Web 表单顶部显示打印对话框吗?请帮忙。

【问题讨论】:

    标签: printdialog


    【解决方案1】:

    这是我现在的解决方案。 (不建议) 如果你能找到另一个,请分享给我,我非常感谢你的帮助。

    1. 初始化一个新的窗体 Form currentForm = new Form();

    2. 显示表格 currentForm.Show();

    3. 激活表单 currentForm.Activate();

    4. 将其 TopMost 设置为 true,以便将表单置于顶部 currentForm.TopMost = true;

    5. 将其设置为焦点 currentForm.Focus()

    6. 设置form.visible = false currentForm.Visible = false;

    7. 开始显示打印对话框 printDialog.ShowDialog(currentForm)

    8. 关闭新表单 currentForm.Close();

         try
              {
      
                using (PrintDialog printDialog = new PrintDialog())
                  {
                      ReportPrintDocument rp = new ReportPrintDocument(rvPermit.ServerReport);
      
                      Form currentForm = new Form();
                      currentForm.Show();
                      currentForm.Activate();
                      currentForm.TopMost = true;
                      currentForm.Focus();
                      currentForm.Visible = false;
      
                  if (printDialog.ShowDialog(currentForm) == DialogResult.OK)
                  {
                      if (PrintReport != null)
                          PrintReport(this, e);
      
                      rp.PrinterSettings = printDialog.PrinterSettings;
                      rp.Print();
                  }
      
                  currentForm.Close();
              }
          }
          catch (Exception)
          {
              // Prevent any error while calling the printer dialog
          }
      

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多