打印页绘制字符串不显示 C#



所以我试图在PrintDocumentPrintPage事件中循环绘制一个字符串:

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]确实包含一个值,我不确定为什么它不显示。我正在循环打印其他字符串和矩形,它们显示在对话框中。如果有人可以帮助我,请在这里发布,谢谢!

编辑:

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

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,但循环应该工作并且代码正在运行。

所以我发现问题是如果我在 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方法放在不同的循环中,不确定为什么它在其他方面不起作用。

Chaneg 将循环控制变量转换为"index"。您的错误在于您没有为循环使用循环控制变量。

相关内容

  • 没有找到相关文章

最新更新