打印创建一个对话框,我不希望这样

时间:2013-05-20 11:52:40

标签: c# winforms screenshot printdocument

使用表单的屏幕截图创建打印选项,因为我需要整个表单。这导致打印输出的附加打印对话框。

这是代码,

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 个答案:

答案 0 :(得分:2)

在致电printDocument1.PrintController = new StandardPrintController()之前添加printDocument1.Print()默认情况下,我认为它使用PrintControllerWithStatusDialog