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
- PersistNameAttribute.cs
- ElasticEase.cs
- FieldValue.cs
- XmlDocumentSerializer.cs
- XmlFormatReaderGenerator.cs
- DefaultAuthorizationContext.cs
- OdbcConnectionPoolProviderInfo.cs
- Guid.cs
- HttpCapabilitiesEvaluator.cs
- ExpressionStringBuilder.cs
- X509ChainElement.cs
- XmlSerializerFormatAttribute.cs
- DefaultValueTypeConverter.cs
- ScriptControlManager.cs
- LogEntry.cs
- FreeFormDesigner.cs
- SafePEFileHandle.cs
- ColorAnimationBase.cs
- PreviewPageInfo.cs
- Function.cs
- ExpandableObjectConverter.cs
- Models.cs
- FileDataSourceCache.cs
- Cursors.cs
- RIPEMD160Managed.cs
- UnionExpr.cs
- EventMetadata.cs
- TraceHandler.cs
- SystemSounds.cs
- Message.cs
- DurableInstanceContextProvider.cs
- ApplicationServiceManager.cs
- Translator.cs
- Aggregates.cs
- IgnoreSectionHandler.cs
- SqlXmlStorage.cs
- HtmlImage.cs
- CuspData.cs
- SafeRegistryHandle.cs
- RTLAwareMessageBox.cs
- DateTimeOffsetStorage.cs
- MultiPropertyDescriptorGridEntry.cs
- BitSet.cs
- AuthenticationModulesSection.cs
- CodeObjectCreateExpression.cs
- MessageSmuggler.cs
- ParserStreamGeometryContext.cs
- MemberAccessException.cs
- NotificationContext.cs
- FamilyTypeface.cs
- SiteMapNodeItemEventArgs.cs
- ExpressionParser.cs
- UntypedNullExpression.cs
- MenuItemAutomationPeer.cs
- WebPartCatalogAddVerb.cs
- ArithmeticException.cs
- StandardBindingOptionalReliableSessionElement.cs
- IsolatedStorage.cs
- X509CertificateCollection.cs
- BmpBitmapEncoder.cs
- SqlCharStream.cs
- UrlParameterReader.cs
- AlphabeticalEnumConverter.cs
- SymbolMethod.cs
- SymbolEqualComparer.cs
- ReflectTypeDescriptionProvider.cs
- Token.cs
- ProvidersHelper.cs
- ProviderUtil.cs
- SessionEndingEventArgs.cs
- ManifestBasedResourceGroveler.cs
- AsymmetricAlgorithm.cs
- XmlNodeReader.cs
- NamespaceEmitter.cs
- DynamicPropertyHolder.cs
- SqlOuterApplyReducer.cs
- CqlLexerHelpers.cs
- XmlValidatingReaderImpl.cs
- PolicyConversionContext.cs
- CacheForPrimitiveTypes.cs
- RolePrincipal.cs
- WorkflowRequestContext.cs
- DataBoundLiteralControl.cs
- BinaryFormatter.cs
- RegexBoyerMoore.cs
- NavigatingCancelEventArgs.cs
- FastEncoderWindow.cs
- Bits.cs
- IntegerCollectionEditor.cs
- HTTPNotFoundHandler.cs
- CancellationToken.cs
- TTSEvent.cs
- CodeTypeReferenceCollection.cs
- SimpleHandlerBuildProvider.cs
- HiddenField.cs
- SortDescriptionCollection.cs
- ErrorHandler.cs
- RsaSecurityKey.cs
- UnauthorizedWebPart.cs
- WebPartTransformerAttribute.cs