Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / CommonUI / System / Drawing / Printing / PrintPreviewGraphics.cs / 1 / PrintPreviewGraphics.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Drawing { using System.Runtime.InteropServices; using System.ComponentModel; using System.Diagnostics; using System; using Microsoft.Win32; using System.Security; using System.Security.Permissions; using System.Drawing.Internal; using System.Drawing.Imaging; using System.Drawing.Text; using System.Drawing.Drawing2D; using System.Drawing.Printing; ////// /// internal class PrintPreviewGraphics { private PrintPageEventArgs printPageEventArgs; private PrintDocument printDocument; public PrintPreviewGraphics(PrintDocument document, PrintPageEventArgs e) { printPageEventArgs = e; printDocument = document; } ///Retrives the printer graphics during preview. ////// /// Gets the Visible bounds of this graphics object. Used during print preview. /// public RectangleF VisibleClipBounds { get { IntPtr hdevMode = printPageEventArgs.PageSettings.PrinterSettings.GetHdevmodeInternal(); using( DeviceContext dc = printPageEventArgs.PageSettings.PrinterSettings.CreateDeviceContext(hdevMode)) { using( Graphics graphics = Graphics.FromHdcInternal(dc.Hdc) ) { if (printDocument.OriginAtMargins) { // Adjust the origin of the graphics object to be at the user-specified margin location // Note: Graphics.FromHdc internally calls SaveDC(hdc), we can still use the saved hdc to get the resolution. int dpiX = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(dc, dc.Hdc), SafeNativeMethods.LOGPIXELSX); int dpiY = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(dc, dc.Hdc), SafeNativeMethods.LOGPIXELSY); int hardMarginX_DU = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(dc, dc.Hdc), SafeNativeMethods.PHYSICALOFFSETX); int hardMarginY_DU = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(dc, dc.Hdc), SafeNativeMethods.PHYSICALOFFSETY); float hardMarginX = hardMarginX_DU * 100 / dpiX; float hardMarginY = hardMarginY_DU * 100 / dpiY; graphics.TranslateTransform(-hardMarginX, -hardMarginY); graphics.TranslateTransform(printDocument.DefaultPageSettings.Margins.Left, printDocument.DefaultPageSettings.Margins.Top); } return graphics.VisibleClipBounds; } } } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Drawing { using System.Runtime.InteropServices; using System.ComponentModel; using System.Diagnostics; using System; using Microsoft.Win32; using System.Security; using System.Security.Permissions; using System.Drawing.Internal; using System.Drawing.Imaging; using System.Drawing.Text; using System.Drawing.Drawing2D; using System.Drawing.Printing; ////// /// internal class PrintPreviewGraphics { private PrintPageEventArgs printPageEventArgs; private PrintDocument printDocument; public PrintPreviewGraphics(PrintDocument document, PrintPageEventArgs e) { printPageEventArgs = e; printDocument = document; } ///Retrives the printer graphics during preview. ////// /// Gets the Visible bounds of this graphics object. Used during print preview. /// public RectangleF VisibleClipBounds { get { IntPtr hdevMode = printPageEventArgs.PageSettings.PrinterSettings.GetHdevmodeInternal(); using( DeviceContext dc = printPageEventArgs.PageSettings.PrinterSettings.CreateDeviceContext(hdevMode)) { using( Graphics graphics = Graphics.FromHdcInternal(dc.Hdc) ) { if (printDocument.OriginAtMargins) { // Adjust the origin of the graphics object to be at the user-specified margin location // Note: Graphics.FromHdc internally calls SaveDC(hdc), we can still use the saved hdc to get the resolution. int dpiX = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(dc, dc.Hdc), SafeNativeMethods.LOGPIXELSX); int dpiY = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(dc, dc.Hdc), SafeNativeMethods.LOGPIXELSY); int hardMarginX_DU = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(dc, dc.Hdc), SafeNativeMethods.PHYSICALOFFSETX); int hardMarginY_DU = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(dc, dc.Hdc), SafeNativeMethods.PHYSICALOFFSETY); float hardMarginX = hardMarginX_DU * 100 / dpiX; float hardMarginY = hardMarginY_DU * 100 / dpiY; graphics.TranslateTransform(-hardMarginX, -hardMarginY); graphics.TranslateTransform(printDocument.DefaultPageSettings.Margins.Left, printDocument.DefaultPageSettings.Margins.Top); } return graphics.VisibleClipBounds; } } } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- CheckBoxList.cs
- PointConverter.cs
- SerializationSectionGroup.cs
- SqlBulkCopyColumnMappingCollection.cs
- AnnotationAdorner.cs
- DocumentSequenceHighlightLayer.cs
- namescope.cs
- GridPatternIdentifiers.cs
- EntityDataSourceColumn.cs
- InitializationEventAttribute.cs
- ToolStripItemGlyph.cs
- ResourcesChangeInfo.cs
- XslCompiledTransform.cs
- MethodRental.cs
- DictionaryBase.cs
- WebServiceAttribute.cs
- EncodingDataItem.cs
- AuthorizationPolicyTypeElementCollection.cs
- TabControl.cs
- LoadRetryAsyncResult.cs
- WebConfigurationManager.cs
- fixedPageContentExtractor.cs
- Types.cs
- NegationPusher.cs
- DbProviderServices.cs
- ContainerControl.cs
- SerializationAttributes.cs
- ServiceContractGenerator.cs
- ExtentKey.cs
- XmlNodeChangedEventArgs.cs
- ConnectionDemuxer.cs
- PathGeometry.cs
- PixelShader.cs
- COM2ComponentEditor.cs
- CommandConverter.cs
- NameValueFileSectionHandler.cs
- MultipartIdentifier.cs
- SqlCommand.cs
- GB18030Encoding.cs
- TypeForwardedToAttribute.cs
- _ScatterGatherBuffers.cs
- ChangeBlockUndoRecord.cs
- SocketException.cs
- SystemIPAddressInformation.cs
- AxisAngleRotation3D.cs
- Monitor.cs
- LineInfo.cs
- XmlSchemaElement.cs
- MediaElementAutomationPeer.cs
- FloaterBaseParaClient.cs
- DesignerSerializationOptionsAttribute.cs
- SynchronizedRandom.cs
- PageContentAsyncResult.cs
- XmlWriterSettings.cs
- InvalidPrinterException.cs
- MaskDescriptors.cs
- PreloadHost.cs
- SubqueryRules.cs
- GeneralTransform3DTo2D.cs
- ScrollItemPattern.cs
- ToggleButton.cs
- Color.cs
- SmtpNtlmAuthenticationModule.cs
- KeyValueConfigurationCollection.cs
- TargetParameterCountException.cs
- PrintingPermission.cs
- DbConnectionFactory.cs
- ExpressionCopier.cs
- XmlSchemaImport.cs
- UrlMappingCollection.cs
- DisableDpiAwarenessAttribute.cs
- XmlSchemaGroup.cs
- ProcessModelInfo.cs
- TextRunCache.cs
- ObjectDataSourceChooseMethodsPanel.cs
- ListViewInsertEventArgs.cs
- CodeTypeConstructor.cs
- Win32KeyboardDevice.cs
- Light.cs
- FormatterServices.cs
- TextParagraphCache.cs
- HttpRawResponse.cs
- GlobalEventManager.cs
- ReadOnlyDataSource.cs
- CoreSwitches.cs
- WinFormsComponentEditor.cs
- TemplateManager.cs
- FontDifferentiator.cs
- SmiConnection.cs
- QilTernary.cs
- VsPropertyGrid.cs
- SudsWriter.cs
- RepeatBehaviorConverter.cs
- EntityDataSourceViewSchema.cs
- SafeBitVector32.cs
- ZipIOLocalFileHeader.cs
- HttpClientChannel.cs
- AutoScrollHelper.cs
- Metafile.cs
- TypeSystemHelpers.cs