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
- XamlTreeBuilder.cs
- ListBox.cs
- IImplicitResourceProvider.cs
- Touch.cs
- DiagnosticTrace.cs
- CompilationLock.cs
- PageAsyncTaskManager.cs
- Color.cs
- OneOfElement.cs
- XmlIlGenerator.cs
- Evidence.cs
- OdbcDataReader.cs
- Inflater.cs
- MobileUserControlDesigner.cs
- ReturnValue.cs
- Polygon.cs
- WebPartUtil.cs
- HTMLTextWriter.cs
- InputProcessorProfiles.cs
- UIElement3DAutomationPeer.cs
- IDQuery.cs
- XmlName.cs
- IdentityValidationException.cs
- UnmanagedMemoryAccessor.cs
- infer.cs
- MethodResolver.cs
- ChannelManagerHelpers.cs
- TreeWalker.cs
- IChannel.cs
- DocumentCollection.cs
- TextDecorationCollectionConverter.cs
- QilSortKey.cs
- DBBindings.cs
- KeySpline.cs
- QilReplaceVisitor.cs
- SafeHandles.cs
- CurrentTimeZone.cs
- SystemDropShadowChrome.cs
- ProfileGroupSettings.cs
- FormsIdentity.cs
- DesignerDataColumn.cs
- PagerSettings.cs
- OleDbConnectionPoolGroupProviderInfo.cs
- RuleSettings.cs
- ProjectionPlan.cs
- _LocalDataStore.cs
- SqlWorkflowInstanceStoreLock.cs
- DataGridColumnReorderingEventArgs.cs
- Lease.cs
- DefaultEvaluationContext.cs
- ProgressChangedEventArgs.cs
- DataControlImageButton.cs
- CallbackCorrelationInitializer.cs
- Triangle.cs
- WSSecureConversation.cs
- Decoder.cs
- PersistenceTypeAttribute.cs
- RetrieveVirtualItemEventArgs.cs
- InstanceNotReadyException.cs
- CreateUserErrorEventArgs.cs
- DBCommand.cs
- ConsoleCancelEventArgs.cs
- NamedPermissionSet.cs
- CommentGlyph.cs
- SessionEndedEventArgs.cs
- CoreSwitches.cs
- StringUtil.cs
- rsa.cs
- ListViewItemMouseHoverEvent.cs
- ContractHandle.cs
- DetailsViewDeletedEventArgs.cs
- WhitespaceSignificantCollectionAttribute.cs
- DataSourceXmlSubItemAttribute.cs
- Vector3D.cs
- Environment.cs
- EncryptedReference.cs
- StandardBindingCollectionElement.cs
- CallbackValidator.cs
- SqlUDTStorage.cs
- Visitors.cs
- WebPartAuthorizationEventArgs.cs
- DataControlFieldHeaderCell.cs
- COMException.cs
- OleAutBinder.cs
- XpsViewerException.cs
- BorderGapMaskConverter.cs
- Mutex.cs
- ListMarkerSourceInfo.cs
- DbParameterCollectionHelper.cs
- ModelItemCollectionImpl.cs
- WindowsButton.cs
- XmlTextWriter.cs
- OleDbConnectionPoolGroupProviderInfo.cs
- RectAnimationUsingKeyFrames.cs
- HyperLinkField.cs
- GeneralTransformGroup.cs
- TimeSpanOrInfiniteConverter.cs
- LineSegment.cs
- StringValidator.cs
- ClientRoleProvider.cs