1

所以我试图在 a 的情况下在循环中绘制一个PrintPage字符串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++;
}

看起来一切正常,调试器显示它在我使用断点时运行,但是当我在 a 中显示文档时PrintPreviewDialog它没有显示。allitems[index] 确实包含一个值,我不确定它为什么不显示。我在循环之外打印其他字符串和矩形,它们显示在对话框中。如果有人可以帮助我,请在此处发布,谢谢!

编辑:

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

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;

编辑2:

好的,所以我使用了:

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

并且只DrawString显示了循环外部,但循环应该可以工作并且代码正在运行。

4

2 回答 2

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方法置于不同的循环中,不知道为什么它不起作用。

于 2012-06-25T07:24:12.350 回答
-1

将循环控制变量更改为“索引”。您的错误是您没有为循环使用循环控制变量。

于 2013-03-09T08:47:59.000 回答