2014-03-05 50 views
0

我目前使用的是System.Windows.Forms。 PrintDialog在ASP.net中的自定義控件上,因爲我想顯示打印對話框並將它的PrinterSettings分配給ReportPrintDocument.PrinterSettings,然後單擊對話框上的確定按鈕。 這裏是我的代碼:無法在asp.net web控件頂部顯示打印對話框

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

我的問題是,在打印對話框總是顯示在Web瀏覽器的背後,我無法知道它顯示與否,直到我最小化的Web瀏覽器。

你知道如何在Web表單的頂部顯示打印對話框嗎?請幫忙。

回答

0

這是我現在的解決方案。 (不建議) 如果你可以找到另一個,請分享給我,我非常感謝你的幫助。

  1. 初始化一個新的窗口形式 Form currentForm = new Form();

  2. 形式展現 currentForm.Show();

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

  4. 設置其最高爲true,所以它會帶來形式到頂部 currentForm.TopMost = true;

  5. 將其設置爲重點 currentForm.Focus()

  6. 設置form.visible =假 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 
        }