Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- MasterPageBuildProvider.cs
- ProxyWebPart.cs
- HtmlUtf8RawTextWriter.cs
- OpCopier.cs
- EntityDataSourceValidationException.cs
- RsaSecurityToken.cs
- DetailsViewModeEventArgs.cs
- Graphics.cs
- AutomationElement.cs
- TemplateControlCodeDomTreeGenerator.cs
- AdornerDecorator.cs
- CodeChecksumPragma.cs
- PaintValueEventArgs.cs
- AppearanceEditorPart.cs
- XmlUtilWriter.cs
- OperationBehaviorAttribute.cs
- IRCollection.cs
- ExpressionBuilder.cs
- CellQuery.cs
- DelegateBodyWriter.cs
- Stack.cs
- TextEditorSelection.cs
- PanelStyle.cs
- InputProviderSite.cs
- _CookieModule.cs
- AuthenticatedStream.cs
- TypeConverterAttribute.cs
- LZCodec.cs
- TriggerAction.cs
- IPEndPointCollection.cs
- Vector.cs
- BindableAttribute.cs
- SpeakCompletedEventArgs.cs
- ToolStripDropDownClosingEventArgs.cs
- DefaultObjectSerializer.cs
- ImageFormatConverter.cs
- MultipartContentParser.cs
- DesignerAttributeInfo.cs
- PageCache.cs
- TrackingProvider.cs
- MasterPageParser.cs
- XmlNotation.cs
- ToolStripLabel.cs
- StateDesigner.LayoutSelectionGlyph.cs
- BitmapEffect.cs
- AuthenticationModuleElement.cs
- AttachedProperty.cs
- AdRotator.cs
- HttpCacheVaryByContentEncodings.cs
- ExceptionUtil.cs
- ExpressionNormalizer.cs
- ConnectionStringsExpressionBuilder.cs
- OleDbConnectionFactory.cs
- ToolStripOverflow.cs
- X509Logo.cs
- assertwrapper.cs
- UriTemplateTrieLocation.cs
- WebSysDescriptionAttribute.cs
- TextUtf8RawTextWriter.cs
- RtfControlWordInfo.cs
- SoapClientProtocol.cs
- MemberCollection.cs
- BooleanAnimationBase.cs
- UiaCoreApi.cs
- RewritingPass.cs
- CatalogZoneAutoFormat.cs
- TextureBrush.cs
- hresults.cs
- CachedBitmap.cs
- WebConfigurationHost.cs
- ResponseBodyWriter.cs
- BitmapMetadata.cs
- IgnoreFileBuildProvider.cs
- DnsPermission.cs
- CompilerWrapper.cs
- HighlightVisual.cs
- CodeArrayCreateExpression.cs
- TemplateContainer.cs
- DataSourceView.cs
- X509CertificateValidator.cs
- DayRenderEvent.cs
- ChangePasswordDesigner.cs
- BamlBinaryWriter.cs
- TokenBasedSet.cs
- QuaternionValueSerializer.cs
- Avt.cs
- Track.cs
- IdentitySection.cs
- PnrpPermission.cs
- ExpressionStringBuilder.cs
- SecurityRuntime.cs
- AsyncStreamReader.cs
- EditingCoordinator.cs
- PropertyEntry.cs
- TextEffect.cs
- DrawListViewSubItemEventArgs.cs
- TransformConverter.cs
- TimersDescriptionAttribute.cs
- UrlPath.cs
- MessageQueueException.cs