So I am trying to draw a string in a loop in the PrintPage event of a 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++;
}
It seems all normal, and the debugger shows that it gets run when I use a breakpoint but when I display the document in a PrintPreviewDialog it does not show up. allitems[index] does contain a value and I am not sure why it is not displaying. I am printing other strings and rectangles outside the loop and they show up in the dialog. If anyone could help me please post here, Thanks!
Edit:
Here are the graphics modes/rendering hints:
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;
Edit 2:
Alright, so I used:
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++;
}
And only the DrawString outside the loop was being displayed but the loop should work and the code is being run.
So I found that the problem was if I am drawing more than once in a for loop like so:
It would not show any of them at all. To fix this I have to have each
DrawStringmethod in a different loop, not sure why it doesn’t work other-wise.