
-----------------------------------
Nathan4102
Thu Oct 10, 2013 6:26 pm

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

-----------------------------------
rdrake
Thu Oct 10, 2013 11:31 pm

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 
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.


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 [url=http://msdn.microsoft.com/en-us/library/System.Drawing.Printing.aspx]entire namespace is full of functionality.

-----------------------------------
Nathan4102
Fri Oct 11, 2013 8:06 am

RE:Printing forms in C#
-----------------------------------
This is the way I already tried, it printed, but with terrible quality.

-----------------------------------
Nathan4102
Fri Oct 11, 2013 1:27 pm

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.
