Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Printing forms in C#
Index -> Programming, C -> C Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Nathan4102




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
rdrake




PostPosted: 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.
Nathan4102




PostPosted: 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.
Nathan4102




PostPosted: 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.
Display posts from previous:   
   Index -> Programming, C -> C Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: