首页 > 解决方案 > System.Runtime.InteropServices.ExternalException:“GDI+ 中发生一般错误。” 在通过 C# 打印文件时

问题描述

我为喀拉拉邦的一座寺庙制作了一个计费软件,用于为向寺庙供品的奉献者打印 rcpt。单击打印按钮时,打印机必须将 rcpt 详细信息打印到表单中。我制作了一个打印按钮和一个打印文档,并将文档编码如下:

private void RCPT_PRINTABLE_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
    e.Graphics.DrawString(RCPTNO.Text, new Font("ML-NILA02_NewLipi", 15, FontStyle.Bold), Brushes.Black, new Point(94 , 109));
    e.Graphics.DrawString(RcptDate.Text, new Font("ML-NILA02_NewLipi", 15, FontStyle.Regular), Brushes.Black, new Point(408, 109));
    e.Graphics.DrawString(NameRcpt.Text, new Font("Times New Roman", 13, FontStyle.Regular), Brushes.Black, new Point(94, 132));
    e.Graphics.DrawString(RCPTSTAR.Text, new Font("ML-NILA02_NewLipi", 15, FontStyle.Regular), Brushes.Black, new Point(408, 132));



    //DATEBOOKING PRINT BEGIN   
    if (Vazhipaad1.Text != "--")
    {
        e.Graphics.DrawString("1. "+Vazhipaad1.Text + "(" + dateTimePicker2.Text + ")"+ "(" + No1.Text + "*" + Rate1.Text + ")", new Font("ML-NILA02_NewLipi", 15, FontStyle.Regular), Brushes.Black, new Point(57, 200) );
        e.Graphics.DrawString("₹" + textBox1.Text, new Font("ML-NILA02_NewLipi", 15, FontStyle.Regular), Brushes.Black, new Point(434, 200));
    }


    if (Vazhipaad2.Text != "--")
    {
        e.Graphics.DrawString("2. "+Vazhipaad2.Text + "(" + dateTimePicker1.Text + ")" + "(" + No2.Text + "*" + Rate2.Text + ")", new Font("ML-NILA02_NewLipi", 15, FontStyle.Regular), Brushes.Black, new Point(57, 234));
        e.Graphics.DrawString("₹" + textBox2.Text, new Font("ML-NILA02_NewLipi", 15, FontStyle.Regular), Brushes.Black, new Point(434, 234));
    }

    if (Vazhipaad3.Text != "--")
    {
        e.Graphics.DrawString("3. "+Vazhipaad3.Text + "(" + dateTimePicker5.Text + ")" + "(" + No3.Text + "*" + Rate3.Text + ")", new Font("ML-NILA02_NewLipi", 15, FontStyle.Regular), Brushes.Black, new Point(57, 265));
        e.Graphics.DrawString("₹" + textBox3.Text, new Font("ML-NILA02_NewLipi", 15, FontStyle.Regular), Brushes.Black, new Point(434, 265));
    }


    e.Graphics.DrawString("₹" + TOTAL.Text, new Font("ML-NILA02_NewLipi", 20, FontStyle.Regular), Brushes.Black, new Point(397, 302));

    e.Graphics.Dispose();

}

但是当执行此代码时,在第二个 if 语句中,第一行出现异常 System.Runtime.InteropServices.ExternalException: 'A generic error occurred in GDI+.' 被系统抛出。我参考了很多网站,但没有找到完美的答案。请帮我!!!!!!!!!!!!!!!

标签: c#vb.net

解决方案


推荐阅读