繁体   English   中英

e.graphics.drawstring在printpreview上显示文本但不打印

[英]e.graphics.drawstring showing text on printpreview but not printing

我正在使用基于c#windows的应用程序。[Visual Studio 2010]

在那我试图打印该法案。

我使用e.Graphics.Drawstring该帐单。

在这里,它向我展示了包含所有适当数据的printpreview。

但是,当我打印出printpreview时,它没有向我显示帐单中的项目。[打印预览的特定部分。 其他数据显示]。

我的代码如下:

e.Graphics.DrawString("Amount", drawFont, Brushes.Black, new RectangleF(tempX + 600, tempY, dataGridView1.Columns[0].Width, dataGridView1.Rows[1].Height), str);

    while (i < dataGridView1.Rows.Count-1)
            {

                if (height > e.MarginBounds.Height)
                {
                    height = 100;
                    width = 100;
                    e.HasMorePages = true;
                    return;
                }
                height += dataGridView1.Rows[i].Height;

                e.Graphics.DrawString((idInCol).ToString(), drawFont, Brushes.Black, new RectangleF(tempX, ((i*22)+(tempY+25)), dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height), str);


                e.Graphics.DrawString(dataGridView1.Rows[i].Cells[2].FormattedValue.ToString().Trim(), drawFont, Brushes.Black, new RectangleF(tempX + 30, ((i * 22) + (tempY +25)), 500, dataGridView1.Rows[0].Height), str);

                e.Graphics.DrawString(dataGridView1.Rows[i].Cells[3].FormattedValue.ToString(), drawFont, Brushes.Black, new RectangleF(tempX + 400, ((i * 22) + (tempY +25)), dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height), drawFormat);
                width += dataGridView1.Columns[0].Width;

                              e.Graphics.DrawString(dataGridView1.Rows[i].Cells[4].FormattedValue.ToString().Trim(), drawFont, Brushes.Black, new RectangleF(tempX + 500, ((i * 22) + (tempY +25)), dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height), drawFormat);
                width += dataGridView1.Columns[0].Width;

                               e.Graphics.DrawString(dataGridView1.Rows[i].Cells[5].FormattedValue.ToString().Trim(), drawFont, Brushes.Black, new RectangleF(tempX + 600, ((i * 22) + (tempY +25)), dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height), drawFormat);
                width += dataGridView1.Columns[0].Width;
                idInCol++;
                i++;
            }

这是我对账单的截图:

在此输入图像描述

在我打印时,它没有向我显示账单细节。 除了那个之外,其他所有数据都显示在打印输出中。

我已粘贴代码(while循环),我从中获取该帐单详细信息(项目,序列号等)。

我的代码中是否有任何遗漏?

要么

我在代码中做错了什么吗?

请帮我。

我知道这是两个月大,你可能发现了这个错误或放弃了。

无论如何我在这里:我假设变量i被声明为全局类。 如果是这种情况,则需要在while循环完成后将i重置为0。

要确认您需要重置i只需调试您的app并在第二次进入该方法时检查i值(真正的打印方法)。 此外,如果你没有预览直接打印它应该工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM