Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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
- PropertyDescriptorCollection.cs
- ListViewEditEventArgs.cs
- RectAnimationUsingKeyFrames.cs
- COM2PropertyBuilderUITypeEditor.cs
- GenericTextProperties.cs
- RenderDataDrawingContext.cs
- SiteMapNodeItem.cs
- SapiRecoInterop.cs
- xmlsaver.cs
- MemberAssignment.cs
- Substitution.cs
- DataGridViewCellErrorTextNeededEventArgs.cs
- Transform3D.cs
- HttpCapabilitiesSectionHandler.cs
- DetailsViewDeleteEventArgs.cs
- TextFormatterImp.cs
- SafeNativeMethodsMilCoreApi.cs
- TextBox.cs
- CodeTypeDeclarationCollection.cs
- ProofTokenCryptoHandle.cs
- Queue.cs
- EntityRecordInfo.cs
- ObjectDisposedException.cs
- TreeNodeStyleCollectionEditor.cs
- DataSourceConverter.cs
- ImportContext.cs
- PluralizationService.cs
- TryExpression.cs
- IdentitySection.cs
- FormView.cs
- ResizeGrip.cs
- Set.cs
- CodeTypeConstructor.cs
- ScriptResourceHandler.cs
- LazyTextWriterCreator.cs
- StreamingContext.cs
- UnsafePeerToPeerMethods.cs
- RoleService.cs
- DataGridViewAccessibleObject.cs
- InnerItemCollectionView.cs
- RectangleConverter.cs
- DataGridViewCellStyleChangedEventArgs.cs
- COM2IPerPropertyBrowsingHandler.cs
- _Events.cs
- ListBoxItem.cs
- CollectionDataContractAttribute.cs
- ConfigXmlDocument.cs
- FixedPageStructure.cs
- NullableFloatMinMaxAggregationOperator.cs
- DBSqlParserColumnCollection.cs
- Context.cs
- UnmanagedMarshal.cs
- View.cs
- XsdBuilder.cs
- ProgressiveCrcCalculatingStream.cs
- AttributeCollection.cs
- SoapInteropTypes.cs
- IsolatedStorageFilePermission.cs
- WebPartConnectVerb.cs
- Thread.cs
- SharedDp.cs
- MenuItemAutomationPeer.cs
- LazyTextWriterCreator.cs
- SpeechAudioFormatInfo.cs
- PersonalizationDictionary.cs
- Typography.cs
- ServiceTimeoutsBehavior.cs
- DispatcherSynchronizationContext.cs
- GeneralTransform2DTo3DTo2D.cs
- ArgumentException.cs
- XslCompiledTransform.cs
- SecureEnvironment.cs
- CellParaClient.cs
- DefaultPropertyAttribute.cs
- DragDrop.cs
- ExpressionCopier.cs
- SRef.cs
- ChunkedMemoryStream.cs
- AssemblyBuilderData.cs
- TagMapCollection.cs
- PolygonHotSpot.cs
- PrintPreviewDialog.cs
- CatalogZone.cs
- Mouse.cs
- GridViewUpdatedEventArgs.cs
- TriggerAction.cs
- XPathNodeInfoAtom.cs
- ZipIOLocalFileDataDescriptor.cs
- KeyFrames.cs
- RuntimeWrappedException.cs
- ServerType.cs
- AsyncOperation.cs
- BlockUIContainer.cs
- Transform3DGroup.cs
- EntityDataSourceReferenceGroup.cs
- StylusDevice.cs
- AnimatedTypeHelpers.cs
- TextServicesHost.cs
- TextUtf8RawTextWriter.cs
- CubicEase.cs