3

使用 MSDN 中关于如何打印 Windows 窗体的代码示例,我有一个修改后的我的,先调出打印机选项然后打印,但我一直收到一个空白页。使用CopyFromScreen,我给出了表单源 X 和 Y 的坐标,但是对于我尝试过的目的地0以及this.Location.X & Y. 有没有另一种方法来捕获图像?

private void printButton_Click(object sender, EventArgs e)
    {
        CaptureScreen();

        printDialog1.AllowSomePages = true;

        printDialog1.ShowHelp = true;

        printDialog1.Document = printDoc1;

        DialogResult result = printDialog1.ShowDialog();

        if (result == DialogResult.OK)
        {
            printDoc1.Print();
        }
    }        

 private void CaptureScreen()
    {
        Graphics myGraphics = this.CreateGraphics();
        Size s = this.Size;
        memoryImage = new Bitmap(s.Width, s.Height, myGraphics);
        Graphics memoryGraphics = Graphics.FromImage(memoryImage);
        memoryGraphics.CopyFromScreen(this.Location.X, this.Location.Y, 0, 0, s);
    }

void printDoc1_PrintPage(object sender, PrintPageEventArgs e)
    {
        e.Graphics.DrawImage(memoryImage, 0, 0);
    }
4

0 回答 0