Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjoerntx/b71397ad942d36758ee7 to your computer and use it in GitHub Desktop.
Save bjoerntx/b71397ad942d36758ee7 to your computer and use it in GitHub Desktop.
/*------------------------------------------------------
** OnBeginPrint
** description: This method overrides the standard
** OnBeginPrint method and sets the from
** and to page values
**
** parameters: standard PrintEventArgs
**----------------------------------------------------*/
protected override void OnBeginPrint(PrintEventArgs e)
{
base.OnBeginPrint(e);
// if PrinterSettings have been specified, check the print ranges
switch (PrinterSettings.PrintRange)
{
case PrintRange.AllPages:
m_currentPage = 0;
m_toPage = m_textControl.Pages - 1;
break;
case PrintRange.SomePages:
m_currentPage = PrinterSettings.FromPage - 1;
m_toPage = PrinterSettings.ToPage - 1;
break;
default:
throw new InvalidOperationException("This print range is not valid.");
}
// switch the page size values based on the page orientation
m_paperSize = (PrinterSettings.DefaultPageSettings.Landscape) ?
new Size(
PrinterSettings.DefaultPageSettings.PaperSize.Height,
PrinterSettings.DefaultPageSettings.PaperSize.Width) :
new Size(
PrinterSettings.DefaultPageSettings.PaperSize.Width,
PrinterSettings.DefaultPageSettings.PaperSize.Height);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment