2013-05-20 46 views
0

創建一個帶有窗體屏幕截圖的打印選項,因爲我確實需要整個窗體。這導致打印輸出的附加打印對話框。打印創建一個對話框,我不需要

下面是代碼,

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e){ 
    var scr = Screen.FromPoint(this.Location); 
     using (var bmp = new Bitmap(scr.WorkingArea.Width, scr.WorkingArea.Height)) 
     { 
      using (var gr = Graphics.FromImage(bmp)) 
      { 
       gr.CopyFromScreen(new Point(scr.WorkingArea.Left, scr.WorkingArea.Top), Point.Empty, bmp.Size); 
      } 
      // Determine scaling 
      float scale = 1.0f; 
      scale = Math.Min(scale, (float)e.MarginBounds.Width/bmp.Width); 
      scale = Math.Min(scale, (float)e.MarginBounds.Height/bmp.Height); 
      // Set scaling and offset 
      e.Graphics.TranslateTransform(e.MarginBounds.Left + (e.MarginBounds.Width - bmp.Width * scale)/2, 
              e.MarginBounds.Top + (e.MarginBounds.Height - bmp.Height * scale)/2); 
      e.Graphics.ScaleTransform(scale, scale); 
      // And draw 
      e.Graphics.DrawImage(bmp, 0, 0); 

}

,如下圖所示其中顯示對話框, Problem Area

請幫助我在這個問題...在此先感謝...

+1

你用什麼打印表格? – Milen

+0

@MilenPavlov PrintDocument控件。錯過了這一行,'private void printDocument1_PrintPage(object sender,System.Drawing.Printing.PrintPageEventArgs e)' – Developer

回答

2

加入printDocument1.PrintController = new StandardPrintController()然後致電printDocument1.Print()默認情況下,我相信它使用PrintControllerWithStatusDialog

+0

非常感謝您的幫助......它的工作......非常感謝您...... – Developer