Printing forms in C#
Author |
Message |
Nathan4102
|
Posted: Thu Oct 10, 2013 6:26 pm Post subject: Printing forms in C# |
|
|
I've learned C#.net for my co-op, but I'm having a bit of trouble printing quality forms. I tried taking a screen cap of the form, then printing the .bmp, but that resulted in really bad quality. I've heard there's a way to draw a form on a printDocument thingy, and then print straight from that, but I haven't been able to find any good information on this. My form has labels, text boxes, radio buttons, check boxes, and a picture frame.
Does anyone know how I can print my forms clearly?
Thanks,
Nathan |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
rdrake
![](http://compsci.ca/v3/uploads/user_avatars/113417932472fc6c9cd916.png)
|
Posted: Thu Oct 10, 2013 11:31 pm Post subject: Re: Printing forms in C# |
|
|
Your computer screen is probably set to 96 DPI, while a low-quality printer will give you at least 300 DPI. This is why the image looks like garbage once printed.
I found some promising information on Google. It looks like you'll basically have some way of triggering a print event, copy the contents of the form.
C#: |
Bitmap memoryImage;
private void CaptureScreen ()
{
Graphics myGraphics = this. CreateGraphics();
Size s = this. Size;
memoryImage = new Bitmap (s. Width, s. Height, myGraphics );
Graphics memoryGraphics = Graphics. FromImage(memoryImage );
memoryGraphics. CopyFromScreen(this. Location. X, this. Location. Y, 0, 0, s );
}
|
You then draw the bitmap to the print canvas and it prints.
C#: |
private void printDocument1_PrintPage(System.Object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(memoryImage, 0, 0);
}
|
You can also let the user change settings, display a print preview, etc. The entire namespace is full of functionality. |
|
|
|
|
![](images/spacer.gif) |
Nathan4102
|
Posted: Fri Oct 11, 2013 8:06 am Post subject: RE:Printing forms in C# |
|
|
This is the way I already tried, it printed, but with terrible quality. |
|
|
|
|
![](images/spacer.gif) |
Nathan4102
|
Posted: Fri Oct 11, 2013 1:27 pm Post subject: RE:Printing forms in C# |
|
|
Solved, I figure out how to draw to a PrintDocument. Its freakishly tedious though, I've been going for hours now and I'm still not finished my one page form. |
|
|
|
|
![](images/spacer.gif) |
|
|