Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8148983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:45:28+00:00 2026-06-06T14:45:28+00:00

So I am trying to draw a string in a loop in the PrintPage

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T14:45:30+00:00Added an answer on June 6, 2026 at 2:45 pm

    So I found that the problem was if I am drawing more than once in a for loop like so:

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

    It would not show any of them at all. To fix this I have to have each DrawString method in a different loop, not sure why it doesn’t work other-wise.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to draw a custom string with color, font, size and alignment. I
i m trying to draw a string with CGContextShowTextAtPoint. CGContextShowTextAtPoint only accepts const char
I am trying to draw a string using quartz 2d. What i am doing
I'm trying to grab a screenshot from a NSView, draw a string on top
I'm trying to draw shapes that will move around the screen using the LunarLander
I'm trying to make a class that would draw objects of my JBox2d's world
I am trying to draw text on a live wallpaper that has a background
I'm trying to draw a String inside a canvas. The text and the position
I am trying to draw a string at a specific point based on the
I want to use core text to draw string that can span over 100

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.