當前位置: 首頁>>代碼示例>>C#>>正文


C# PrintPageEventArgs.SetGraphics方法代碼示例

本文整理匯總了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);			
		}
開發者ID:nlhepler,項目名稱:mono,代碼行數:52,代碼來源:PrintDocument.cs


注:本文中的System.Drawing.Printing.PrintPageEventArgs.SetGraphics方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。