Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / CommonUI / System / Drawing / Printing / PrintPreviewGraphics.cs / 1305376 / 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; using System.Runtime.Versioning; ////// /// 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 { [ResourceExposure(ResourceScope.None)] [ResourceConsumption(ResourceScope.Process, ResourceScope.Process)] 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
- HtmlElement.cs
- SiteMapPath.cs
- CollectionBuilder.cs
- RecommendedAsConfigurableAttribute.cs
- Utils.cs
- SpecularMaterial.cs
- CanonicalizationDriver.cs
- HwndSourceKeyboardInputSite.cs
- QuestionEventArgs.cs
- ProxyAssemblyNotLoadedException.cs
- ColumnHeader.cs
- Compress.cs
- ObjectReaderCompiler.cs
- PropertyInformationCollection.cs
- ExplicitDiscriminatorMap.cs
- Blend.cs
- RelationalExpressions.cs
- TextComposition.cs
- BCryptSafeHandles.cs
- DataGridViewBindingCompleteEventArgs.cs
- basemetadatamappingvisitor.cs
- WindowsStreamSecurityElement.cs
- RenderTargetBitmap.cs
- SqlDataRecord.cs
- DefaultBindingPropertyAttribute.cs
- IndexingContentUnit.cs
- BrowserCapabilitiesCodeGenerator.cs
- StreamMarshaler.cs
- CompatibleIComparer.cs
- ExternalDataExchangeService.cs
- CryptoApi.cs
- RtfToXamlReader.cs
- BehaviorService.cs
- EventHandlersStore.cs
- NamespaceQuery.cs
- base64Transforms.cs
- AsymmetricSignatureFormatter.cs
- PageFunction.cs
- CapiNative.cs
- SqlTopReducer.cs
- DataGridViewRowStateChangedEventArgs.cs
- FormatterConverter.cs
- AttributeQuery.cs
- UsernameTokenFactoryCredential.cs
- Activity.cs
- DesignTimeResourceProviderFactoryAttribute.cs
- ProcessRequestArgs.cs
- grammarelement.cs
- DataServiceException.cs
- DesignerAttribute.cs
- DateTimeConverter2.cs
- DispatchChannelSink.cs
- WebPartDisplayModeCollection.cs
- WindowInteractionStateTracker.cs
- AllowedAudienceUriElement.cs
- CompatibleIComparer.cs
- SHA384CryptoServiceProvider.cs
- FileUtil.cs
- SyndicationFeedFormatter.cs
- LiteralControl.cs
- DecoderFallbackWithFailureFlag.cs
- SelectionService.cs
- SHA512Managed.cs
- KnownTypes.cs
- PropertyCollection.cs
- EndPoint.cs
- Scanner.cs
- DataMisalignedException.cs
- DataGridViewAccessibleObject.cs
- ColorConverter.cs
- WebAdminConfigurationHelper.cs
- DocumentEventArgs.cs
- TdsParserStateObject.cs
- OrderedDictionaryStateHelper.cs
- DataTransferEventArgs.cs
- HttpResponseHeader.cs
- TextWriterTraceListener.cs
- Keyboard.cs
- SelectionHighlightInfo.cs
- XMLSchema.cs
- SynchronizedReadOnlyCollection.cs
- XPathArrayIterator.cs
- _emptywebproxy.cs
- OleDbEnumerator.cs
- OdbcConnectionHandle.cs
- XmlAnyAttributeAttribute.cs
- NamespaceMapping.cs
- MachineKeySection.cs
- sqlstateclientmanager.cs
- EventNotify.cs
- CheckBoxBaseAdapter.cs
- SchemaImporterExtensionElement.cs
- BamlLocalizabilityResolver.cs
- SqlDataSourceSelectingEventArgs.cs
- _SingleItemRequestCache.cs
- SQLGuid.cs
- CollectionBuilder.cs
- PrincipalPermission.cs
- MonitoringDescriptionAttribute.cs
- GatewayDefinition.cs