无法在asp.net Web控件的顶部显示打印对话框

时间:2014-03-05 15:55:42

标签: printdialog

我目前在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浏览器后面,在我最小化Web浏览器之前我无法知道它是否显示。

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

1 个答案:

答案 0 :(得分:0)

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

  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
        }