Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/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
C# 4.0 无法在c#windows应用程序中打印面板_C# 4.0_Windows Applications - Fatal编程技术网

C# 4.0 无法在c#windows应用程序中打印面板

C# 4.0 无法在c#windows应用程序中打印面板,c#-4.0,windows-applications,C# 4.0,Windows Applications,您好,我正在windows应用程序中打印面板。当我单击打印面板时,它在打印日志中单击打印后打开打印对话框,它抛出异常。 System.CompoentModel.Win32Exception{"Access is denied"} 这是我正在使用的代码 Bitmap MemoryImage; private void btnPrint_Click(object sender, EventArgs e) { panel1.BackColor = Color.Wh

您好,我正在windows应用程序中打印面板。当我单击打印面板时,它在打印日志中单击打印后打开打印对话框,它抛出异常。

System.CompoentModel.Win32Exception{"Access is denied"}
这是我正在使用的代码

Bitmap MemoryImage;

    private void btnPrint_Click(object sender, EventArgs e)
    {
        panel1.BackColor = Color.White;
        printDialog1.Document = printDocument1;

        if (printDialog1.ShowDialog() == DialogResult.OK)
        {
            printDocument1.Print();
        }
    }

    private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
    {
        Rectangle pagearea = e.PageBounds;
        e.Graphics.DrawImage(MemoryImage, (panel1.Width / 2) - (this.panel1.Width / 2), this.panel1.Location.Y);

    }
请让我知道如何解决这个问题

提前谢谢

试试看

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            System.Drawing.Bitmap MemoryImage = new System.Drawing.Bitmap(panel1.Width, panel1.Height);
            Rectangle pagearea = e.PageBounds;
            panel1.DrawToBitmap(MemoryImage, panel1.ClientRectangle);
            e.Graphics.DrawImage(MemoryImage, (pagearea.Width / 2) - (this.panel1.Width / 2), this.panel1.Location.Y);
        }

您在windows xp和windows 7中都能看到这一点吗?可能是用户访问控制问题这与您的代码无关,这是您机器上的配置问题。请尝试使用其他打印机定位问题,并向LAN管理员或IT人员寻求帮助。