Printing to printer in C#

I want to print a string directly to the printer with C# 3 times on 3 differents lines, how can I do it?

Let's use this string "Hello World".

I also wan't to change the Font and the boldness of line #2, if it's possible.


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I don't think you can do this with only 3 lines but here is some sample code:
using System.Drawing.Printing.PrintDocument;
using System.Drawing;

//this is global
private Font printFont;
private string line;

//repeat this section for each page and changee font as needed
printFont = new Font("Arial", 10, FontStyle.Bold);
line = "hello world";
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(this.pd_printpage);

//in pd_printpage(object sender, PrintPageEventArgs ev)
ev.Graphics.DrawString(line, printFont, Brushes.Black, 0, 0);

Printing multiple lines on 1 page is a little more difficult

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bob LearnedCommented:
In order to print on separate lines, you need to measure the text height.  

Put this code into a form:

    public int TextHeight(string text, Font font)

      Graphics gr = this.CreateGraphics();

      int height = (int) gr.MeasureString(text, font).Height;


      return height;


Wait, when you say 3 different lines do you mean the first page has hello world on the first line while the second page has it on the second line etc?
if so do this:

change it to ev.Graphics.DrawString(line, printFont, Brushes.Black, 0, yPos);
where yPos is the line number you want to print it on * printFont.GetHeight(ev.Graphics);
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.