Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
Print panel control as portrait and landscape because I am loading print setting from back end so it will effect in to the printing.
Posted
Comments
Sergey Alexandrovich Kryukov 26-May-15 2:39am    
What's wrong with reading original MSDN documentation?
What have you tried so far?
—SA

1 solution

Here is the idea: you can know it, but you don't really need to tell "portrait" from "landscape". You only need to know the paper size, which you will always know from the page information. You need to know the size anyway, to render the printing graphics correctly.

You do all printing using the class :
https://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument%28v=vs.110%29.aspx[^].

Now, please look at the code sample and pay attention how the event PrintPage is handled. First of all, the instance of PrintPageEventArgs is passed to your handler. Look at this type:
https://msdn.microsoft.com/en-us/library/system.drawing.printing.printpageeventargs%28v=vs.110%29.aspx[^].

As you can see, the event arguments include such data as MarginBounds and PageBounds. You can use this layout information to directly build the layout for the data rendered on print. But if you want, you still get the property PrintPageEventArgs.PageSettings. From this property, you know if this is "portrait" or "landscape":
https://msdn.microsoft.com/en-us/library/system.drawing.printing.printpageeventargs.pagesettings%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.drawing.printing.pagesettings%28v=vs.110%29.aspx[^].

That's all.

—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