简体   繁体   中英

e.graphics.drawstring showing text on printpreview but not printing

I am working with c# windows based application.[Visual Studio 2010]

In that i am trying to print the bill.

I have formed that bill using e.Graphics.Drawstring .

In this it is showing me printpreview with all the appropriate data.

But, when i take printout of that printpreview, its not showing me items in the bill.[Particular part of print preview. Other data is showing].

My code is as follows:

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++;
            }

Here is my screenshot of bill:

在此输入图像描述

In this its not showing me bill particulars when i take print out. Every other data is shown in the printout except that one.

I have pasted the code (while loop) from which i fetches that bill particulars(items,serial nums,etc).

Is there anything missing in my code?

or

Have I done anything wrong in the code?

Please help me.

I know this is two month old and that you probably found the bug or gave up.

Anyway here I go : Here I'm assuming the variable i is declared globaly to the class. If it's the case you need to reset i to 0 after the while loop is done.

To confirm that you need to reset i simply debug you app and check i value the second time you go into that method (the real printing one). Also if you directly print without preview it should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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