Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Printing CaptureScreen()工作,已验证,但事件打印页不工作';t、 我错过什么了吗?_Printing - Fatal编程技术网

Printing CaptureScreen()工作,已验证,但事件打印页不工作';t、 我错过什么了吗?

Printing CaptureScreen()工作,已验证,但事件打印页不工作';t、 我错过什么了吗?,printing,Printing,这是我的打印代码。单击“打印”并显示对话框。如果单击“确定”,则会启动捕获屏幕。位图内存图像成为当前窗体显示的位图。我验证了它的正确性,并且成功地捕获了图像 最后是printDocument.Print()。只打印一个空白页。我试着把它改成e.Graphics.Color(灰色);还是没有运气,只印了一页空白 显然,与打印机的通信是良好的。我的猜测是,页面实际上是在图像被附加之前打印的,但是我以前从来没有为打印编码过,所以我不知道如何重新设置代码的范围 使用系统、绘图、打印 //显示打印对话框(

这是我的打印代码。单击“打印”并显示对话框。如果单击“确定”,则会启动捕获屏幕。位图内存图像成为当前窗体显示的位图。我验证了它的正确性,并且成功地捕获了图像

最后是printDocument.Print()。只打印一个空白页。我试着把它改成e.Graphics.Color(灰色);还是没有运气,只印了一页空白

显然,与打印机的通信是良好的。我的猜测是,页面实际上是在图像被附加之前打印的,但是我以前从来没有为打印编码过,所以我不知道如何重新设置代码的范围

使用系统、绘图、打印

//显示打印对话框(非常有用)

//捕获屏幕(也适用)

//从捕获的屏幕提取图像(不工作)


这段代码在我的打印机上运行良好。
    private void button2_Click(object sender, EventArgs e)
    {         
        PrintDialog printDialog1 = new PrintDialog();
        printDialog1.Document = printDocument1;
        DialogResult result = printDialog1.ShowDialog();
        if (result == DialogResult.OK)
        {
            CaptureScreen();
            printDocument1.Print();
            //this.Close();
        }
    }

    Bitmap memoryImage;
    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);
    }
    private void printDocument1_PrintPage(System.Object sender,
           System.Drawing.Printing.PrintPageEventArgs e)
    {
        e.Graphics.DrawImage(memoryImage, 0, 0);
    }