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
- ViewBase.cs
- CacheHelper.cs
- ReferentialConstraint.cs
- assertwrapper.cs
- PreviewKeyDownEventArgs.cs
- XmlNodeChangedEventArgs.cs
- Rotation3D.cs
- ProxyGenerationError.cs
- Function.cs
- ObjectStateEntryDbDataRecord.cs
- TrackingDataItem.cs
- MessageCredentialType.cs
- SafeRightsManagementPubHandle.cs
- ObjectStorage.cs
- DeleteMemberBinder.cs
- DataGridCellsPresenter.cs
- SpellCheck.cs
- RangeValuePattern.cs
- DataGridPreparingCellForEditEventArgs.cs
- COMException.cs
- ConfigurationElementCollection.cs
- ResourceDescriptionAttribute.cs
- TreeNodeCollection.cs
- SoapException.cs
- RawAppCommandInputReport.cs
- GeneralTransform2DTo3DTo2D.cs
- RoutedEventValueSerializer.cs
- DataGridHelper.cs
- NamedPipeTransportSecurity.cs
- RoleGroup.cs
- TrackingCondition.cs
- ExpressionLink.cs
- WindowsHyperlink.cs
- Attributes.cs
- LiteralControl.cs
- ListViewAutomationPeer.cs
- DataGridAddNewRow.cs
- DbConnectionPoolCounters.cs
- ListViewItem.cs
- Int32AnimationBase.cs
- RoleManagerModule.cs
- SafeNativeMethods.cs
- FacetEnabledSchemaElement.cs
- WebBaseEventKeyComparer.cs
- MissingSatelliteAssemblyException.cs
- HttpCookie.cs
- EventHandlersStore.cs
- ServiceHostingEnvironment.cs
- HierarchicalDataTemplate.cs
- AccessDataSourceView.cs
- EditorPartCollection.cs
- CanonicalXml.cs
- GreenMethods.cs
- Accessors.cs
- RequestCachePolicy.cs
- ScriptControlDescriptor.cs
- ScriptingJsonSerializationSection.cs
- ParameterSubsegment.cs
- GenericUriParser.cs
- OleDbError.cs
- PagerStyle.cs
- HtmlInputRadioButton.cs
- SafeNativeMethods.cs
- PersianCalendar.cs
- MetadataCollection.cs
- FixedSchema.cs
- PeerInvitationResponse.cs
- DynamicPropertyHolder.cs
- TransformDescriptor.cs
- FtpRequestCacheValidator.cs
- IconConverter.cs
- RTLAwareMessageBox.cs
- DateTime.cs
- StrokeNodeOperations2.cs
- OdbcEnvironmentHandle.cs
- BindingMemberInfo.cs
- SqlServices.cs
- Mutex.cs
- LateBoundBitmapDecoder.cs
- DocumentGridPage.cs
- WebPartEditorOkVerb.cs
- XmlLangPropertyAttribute.cs
- String.cs
- InvalidComObjectException.cs
- ResourceDisplayNameAttribute.cs
- BrowserDefinition.cs
- XmlReader.cs
- Calendar.cs
- _NestedSingleAsyncResult.cs
- StringCollectionMarkupSerializer.cs
- GenericNameHandler.cs
- Substitution.cs
- ParameterBuilder.cs
- MimeBasePart.cs
- _SafeNetHandles.cs
- WebPartDescription.cs
- SqlDeflator.cs
- RoleGroup.cs
- XmlnsCompatibleWithAttribute.cs
- WebSysDisplayNameAttribute.cs