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);

}

显示如下所示的对话框, 问题领域

请在这个问题上帮助我...在此先感谢...

4

1 回答 1

2

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

于 2013-05-20T12:32:30.093 回答