本文整理匯總了C#中System.Drawing.Printing.PrintPageEventArgs.SetGraphics方法的典型用法代碼示例。如果您正苦於以下問題:C# PrintPageEventArgs.SetGraphics方法的具體用法?C# PrintPageEventArgs.SetGraphics怎麽用?C# PrintPageEventArgs.SetGraphics使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Drawing.Printing.PrintPageEventArgs
的用法示例。
在下文中一共展示了PrintPageEventArgs.SetGraphics方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Print
// methods
public void Print(){
PrintEventArgs printArgs = new PrintEventArgs();
this.OnBeginPrint(printArgs);
if (printArgs.Cancel)
return;
PrintController.OnStartPrint(this, printArgs);
if (printArgs.Cancel)
return;
Graphics g = null;
if (printArgs.GraphicsContext != null) {
g = Graphics.FromHdc (printArgs.GraphicsContext.Hdc);
printArgs.GraphicsContext.Graphics = g;
}
// while there are more pages
PrintPageEventArgs printPageArgs;
do
{
QueryPageSettingsEventArgs queryPageSettingsArgs = new QueryPageSettingsEventArgs (
DefaultPageSettings.Clone () as PageSettings);
OnQueryPageSettings (queryPageSettingsArgs);
PageSettings pageSettings = queryPageSettingsArgs.PageSettings;
printPageArgs = new PrintPageEventArgs(
g,
pageSettings.Bounds,
new Rectangle(0, 0, pageSettings.PaperSize.Width, pageSettings.PaperSize.Height),
pageSettings);
// TODO: We should create a graphics context for each page since they can have diferent paper
// size, orientation, etc. We use a single graphic for now to keep Cairo using a single PDF file.
printPageArgs.GraphicsContext = printArgs.GraphicsContext;
Graphics pg = PrintController.OnStartPage(this, printPageArgs);
// assign Graphics in printPageArgs
printPageArgs.SetGraphics(pg);
if (!printPageArgs.Cancel)
this.OnPrintPage(printPageArgs);
PrintController.OnEndPage(this, printPageArgs);
if (printPageArgs.Cancel)
break;
} while (printPageArgs.HasMorePages);
this.OnEndPrint(printArgs);
PrintController.OnEndPrint(this, printArgs);
}