Click here to Skip to main content
15,889,858 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
My question is how do you create printEventArgs?

The way I have been getting the printEventArgs was through the print_page event from the System.Drawing.Printing.PrintDocument class.


or is there a way to trigger print_page event without actually printing?

C#
System.Drawing.Printing.PrintDocument printDocument1 = new System.Drawing.Printing.PrintDocument();


printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument1_printPage);

System.Drawing.Printing.PrintPageEventArgs ev = new System.Drawing.Printing.PrintPageEventArgs(/* I Can't Create the graphics object...*/);

private void printDocument1_printPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
/*
All My Graphics Stuff...
*/
}


Please feel free to post any Suggestions that could lead to a solution.

Thank You
Posted

1 solution

Wrong question. If you print, you never create this object; the library System.Drawing.Printing always does that when invoking the event. You cannot invoke it in principle. Every event can only be invoked in its declaring type. You cannot even write a derived class and invoke the event declared in base class. This is an important fool-proof feature of events (one of the features making them different from "regular" delegate instances).

And you never actually need that. In your case, the event arguments are always passed to your event handler. Look at the code sample: http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900