Anyone have any good links to tutorials for printing with C#?

I need to mimic a form that we have. It's a rather complex form, so if you know of a tutorial that is better than just printing rows and columns of data would be greatly appreciative!

Recommended Answers

All 6 Replies

Have you tried just Googling "C# Printing"? Seems there's a lot of good results from that.

Have you tried just Googling "C# Printing"? Seems there's a lot of good results from that.

Yep. Been there, tried that, consumed aspirin to relieve headache and repeated ad nauseum...

The thing I don't get is how to create forms that don't just contain text. All of the examples that I have read deal with text only, setting margins and fonts and page orientation...that's wonderful and great. But what about drawing lines? Creating a box 4 inches from the left margin and 6 inches from the right where the top and bottom is 2 inches and the sides are 1? Then filling that box with text, or an image or whatever else?

The tutorials are all so basic and don't cover any of those things, at least not the ones I have found. The ones that might touch on it are from 7 years ago and are poorly written.

If no one has a link, is there a good book that might touch on this subject?

Attached is an image of a printed form. I need my application to print something similar to this. (confidential info blocked out).

Any help?

http://msdn.microsoft.com/en-us/library/6he9hz8c.aspx

That link should get you to where you could print out the actual form.

As for printing an actual form-like document from an application, there are a couple ways that I can think of to do it, both probably being inefficient as I'm not that good at C# yet.

First, you can design the form in another application like Publisher or InfoPath. Print that out and use that as your paper for printing out form data from your actual form application. It may take you a while to nail down your positioning, but it would work. I know medical offices have applications that do something like this as HCFA forms are done this way many times.

Second, you could spend some time designing the form using the printing framework.

void PrintDoc_PrintPage(object sender, PrintPageEventArgs e)
{
    e.Graphics.DrawLine(new Pen(Color.Aqua, 2.0), new Point(5, 3), new Point(10, 6));
    e.Graphics.DrawRectangle(new Pen(Color.Azure), 250, 65, 20, 15);
    e.Graphics.DrawString(textBox.Text, new Font("Times New Roman", 12), Brushes.Bisque, 250, 65);
    ...
}
commented: Good advice +4

http://msdn.microsoft.com/en-us/library/6he9hz8c.aspx

That link should get you to where you could print out the actual form.

As for printing an actual form-like document from an application, there are a couple ways that I can think of to do it, both probably being inefficient as I'm not that good at C# yet.

First, you can design the form in another application like Publisher or InfoPath. Print that out and use that as your paper for printing out form data from your actual form application. It may take you a while to nail down your positioning, but it would work. I know medical offices have applications that do something like this as HCFA forms are done this way many times.

Second, you could spend some time designing the form using the printing framework.

void PrintDoc_PrintPage(object sender, PrintPageEventArgs e)
{
    e.Graphics.DrawLine(new Pen(Color.Aqua, 2.0), new Point(5, 3), new Point(10, 6));
    e.Graphics.DrawRectangle(new Pen(Color.Azure), 250, 65, 20, 15);
    e.Graphics.DrawString(textBox.Text, new Font("Times New Roman", 12), Brushes.Bisque, 250, 65);
    ...
}

That's a ton of help! Thank you!

One quick question though....you are referencing points to draw lines and other graphics....what are those referenced to? That seems to be my biggest hold up.....is there a piece of paper I can print out that shows points of reference so that I can hand draw my form and then enter the points of reference? I guess what I am after is the "resolution" of the paper...is that something that can be set?

That I'm not too sure about. You may want to mess around with the points/dimensions a little bit to see what fits your requirements but mostly what works. You may be able to search for the ratio between application coordinates and actual distance. Print something out, see where it lands on the piece of paper, put the paper back in, oriented differently and try again. There's got to be a way to do it without trial and error, but I don't know how.

That I'm not too sure about. You may want to mess around with the points/dimensions a little bit to see what fits your requirements but mostly what works. You may be able to search for the ratio between application coordinates and actual distance. Print something out, see where it lands on the piece of paper, put the paper back in, oriented differently and try again. There's got to be a way to do it without trial and error, but I don't know how.

I'll see what I can find :)

Thanks! If I figure it out I'll let you know!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.