簡體   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