C# e、 graphics.drawstring在打印预览中显示文本,但不打印
我正在使用基于c#windows的应用程序。[Visual Studio 2010] 因为我想打印账单 我用C# e、 graphics.drawstring在打印预览中显示文本,但不打印,c#,.net,winforms,printing,C#,.net,Winforms,Printing,我正在使用基于c#windows的应用程序。[Visual Studio 2010] 因为我想打印账单 我用e.Graphics.Drawstring组成了那张账单 在这里,它向我展示了带有所有适当数据的printpreview 但是,当我从打印预览中打印出来时,它不会显示账单中的项目。[打印预览的特定部分。其他数据正在显示] 我的代码如下: e.Graphics.DrawString("Amount", drawFont, Brushes.Black, new RectangleF(tempX
e.Graphics.Drawstring
组成了那张账单
在这里,它向我展示了带有所有适当数据的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++;
}
e.Graphics.DrawString(“Amount”、drawFont、brush.Black、新矩形(tempX+600、tempY、dataGridView1.Columns[0]、Width、dataGridView1.Rows[1].Height)、str);
而(i东边缘边界高度)
{
高度=100;
宽度=100;
e、 HasMorePages=true;
返回;
}
高度+=dataGridView1.行[i].高度;
e、 Graphics.DrawString((idicol).ToString(),drawFont,Brush.Black,新矩形(tempX,((i*22)+(tempY+25)),dataGridView1.Columns[0]。宽度,dataGridView1.Rows[0]。高度),str);
e、 Graphics.DrawString(dataGridView1.Rows[i].Cells[2].FormattedValue.ToString();
e、 Graphics.DrawString(dataGridView1.Rows[i].Cells[3].FormattedValue.ToString()、drawFont、Bruss.Black、新矩形(tempX+400、((i*22)+(tempY+25))、dataGridView1.Columns[0].Width、dataGridView1.Rows[0].Height、drawFormat);
宽度+=dataGridView1。列[0]。宽度;
e、 Graphics.DrawString(dataGridView1.Rows[i].Cells[4].FormattedValue.ToString().Trim()、drawFont、Brush.Black、新矩形(tempX+500、((i*22)+(tempY+25))、dataGridView1.Columns[0].Width、dataGridView1.Rows[0].Height)、drawFormat);
宽度+=dataGridView1。列[0]。宽度;
e、 Graphics.DrawString(dataGridView1.Rows[i].Cells[5].FormattedValue.ToString().Trim()、drawFont、Brush.Black、新矩形(tempX+600、((i*22)+(tempY+25))、dataGridView1.Columns[0].Width、dataGridView1.Rows[0].Height)、drawFormat);
宽度+=dataGridView1。列[0]。宽度;
吲哚美辛++;
i++;
}
这是我的比尔截图:
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
只需调试您的应用程序,并在第二次使用该方法(真正的打印方法)时检查i
值。另外,如果直接打印而不进行预览,它应该可以工作。代码中明显缺少的是BeginPrint事件处理程序。需要将“i”变量重置回0。这对我有帮助+1.我添加了一个Begin Print事件,并将变量初始化为0。这解决了问题。我开始悬赏这个答案。@pkkg为什么你开始悬赏,当你的问题得到解决。悬赏的目的是吸引未解决问题的答案。