PrintPage绘制字符串不显示C#

时间:2012-06-23 12:14:59

标签: c# graphics printdocument

所以我试图在PrintPage的{​​{1}}事件的循环中绘制一个字符串:

PrintDocument

看起来一切正常,调试器显示它在我使用断点时运行但是当我在for (int c = 0; c < currentwords; c++) { // index is a global int that starts at 0 and f9 is a font with size 9 ev.Graphics.DrawString(allitems[index], f9, Brushes.Black, new Point(100, 100)); // I used new Point(100, 100) for debugging purposes but normally I would // do some calculating to see where it is to be printed index++; } 中显示文档时它没有显示。 PrintPreviewDialog 确实包含一个值,我不确定它为什么不显示。我正在打印其他字符串和矩形外部循环,它们出现在对话框中。如果有人可以帮助我,请在这里发帖,谢谢!

编辑:

以下是图形模式/渲染提示:

allitems[index]

编辑2:

好吧,所以我用过:

ev.Graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
ev.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
ev.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
ev.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
ev.Graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;

仅显示循环外的ev.Graphics.DrawString(allitems[0], f9, Brushes.Black, new Point(100, 100)); for (int c = 0; c < currentwords; c++) { // index is a global int that starts at 0 and f9 is a font with size 9 ev.Graphics.DrawString(allitems[index], f9, Brushes.Black, new Point(100, 100)); // I used new Point(100, 100) for debugging purposes but normally I would // do some calculating to see where it is to be printed index++; } ,但循环应该正常并且代码正在运行。

2 个答案:

答案 0 :(得分:0)

所以我发现问题是如果我在for循环中多次绘制这样:

for (int c = 0; c < currentwords; c++)
{
    ev.Graphics.DrawString(allitems[index], f9, Brushes.Black, 100, 100);
    ev.Graphics.DrawString(allqty[index], f9, Brushes.Black, new Point(200, 200);
    ev.Graphics.DrawString((allprices[index].Contains('$')) ? allprices[index] : "$" + allprices[index], f9, Brushes.Black, 300, 300);
}

根本不会显示任何一个。要解决这个问题,我必须将每个DrawString方法放在不同的循环中,不确定为什么它在其他方面不起作用。

答案 1 :(得分:-1)

将循环控制变量更改为'index'。你的错误是你没有使用循环控制变量进行循环。