Hi
Is there any example of printing a form
having different lables on it?
thanks
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Mike GoldPosted Aug 7, 2007, 12:34 AM
If you have a choice, I'd consider switching to VS2005 which has the DrawToBitmap command for a form.
Drawing a panel isn't going to be any easier. I wrote an article a while back that proposed a strategy for printing form controls (before vs2005's DrawToBitmap). Here is the link:
http://www.c-sharpcorner.com/UploadFile/mgold/HowToPrintingFormControlsinCSharpand.NET11212005063649AM/HowToPrintingFormControlsinCSharpand.NET.aspx
Felipe MarksPosted Aug 6, 2007, 6:11 AM
HI Mike
Thanks for the help.
I think printing a form's just complicating things more for me. Would printing a panel on a form be an easier thing to do?
thanks
Mike GoldPosted Aug 5, 2007, 4:58 PM
It's because you are using VS2003
If you want to draw the form from vs2003, you'll need to capture the screen with unmanaged code
See this article:
http://www.c-sharpcorner.com/UploadFile/perrylee/ScreenCapture11142005234547PM/ScreenCapture.aspx
Best,
Felipe MarksPosted Aug 3, 2007, 4:37 AM
Hi Mike
I did all that.. I used a button event to call the printDocument1.Print() method. And calling the DrawFormSurface from the PrintPage eventhandler.
Im still getting these errors though:
An object reference is required for the nonstatic field, method, or property 'System.Windows.Forms.Control.Height'
'TicketAppGui.Form1' does not contain a definition for 'DrawToBitmap'
I also included: System.Drawing.Printing.. Is there maybe something else?
Or is it because im using VS2003?
thanks,
Mike GoldPosted Aug 2, 2007, 4:29 PM
make sure you are printing the form after the Form Load event so you can make sure the form width is established. The best way to do this is by putting a button on the form that calls the printDocument1.Print() method.
you should call the DrawFormSurface from the PrintPage eventhandler. (the PrintPage event handler that was generated by dragging a PrintDocument component from the toolbox into the form and double clicking on it.
Also printing a form is described in our new book selling for $12 on this site. I believe the source is available for it as well.
Felipe MarksPosted Aug 2, 2007, 4:16 AM
Good day
Thanks for the assistance Mike. I seem to be getting errors using the code though. form1.width isnt working. And is there any code I need to add in the PrintPage?
thanks
Mike GoldPosted Aug 1, 2007, 7:07 PM
Not sure if this is what you are asking, but to print a form,
1) drag the PrintDocument object onto the form
2) double click on the printDocument1 object to get a PrintPage event handler
3) Add the following code
private void DrawFormSurface(System.Drawing.Printing.PrintPageEventArgs e)
{
// create a bitmap the size of the form
Bitmap bmp = new Bitmap(form1.Width, form1.Height);
// draw the form image to the bitmap
form1.DrawToBitmap(bmp, new Rectangle(0, 0, form1.Width, form1.Height));
// draw the bitmap image of the form onto the graphics surface
e.Graphics.DrawImage(bmp, new Point(0, 0));
}
4) call printDocument1.Print() from your menu event handler