Code:
/ 4.0 / 4.0 / 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. //------------------------------------------------------------------------------ //// 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
- CharacterBufferReference.cs
- TypeRefElement.cs
- ProcessingInstructionAction.cs
- PageHandlerFactory.cs
- DataSourceHelper.cs
- DataRow.cs
- TrustManager.cs
- GPStream.cs
- DeclarationUpdate.cs
- TextRunCacheImp.cs
- NamespaceTable.cs
- TransportContext.cs
- ChildTable.cs
- Columns.cs
- DisplayMemberTemplateSelector.cs
- TextProperties.cs
- IsolatedStorageException.cs
- FontDifferentiator.cs
- IdentifierCollection.cs
- ClientTarget.cs
- SpotLight.cs
- RenderDataDrawingContext.cs
- ConfigurationSectionCollection.cs
- QueryOutputWriter.cs
- CdpEqualityComparer.cs
- FrameworkRichTextComposition.cs
- ToolStripSeparatorRenderEventArgs.cs
- PerformanceCounterPermissionAttribute.cs
- SpotLight.cs
- SqlStatistics.cs
- IEnumerable.cs
- WebBrowserSiteBase.cs
- DodSequenceMerge.cs
- BufferedGraphics.cs
- PageWrapper.cs
- KnownBoxes.cs
- RuleCache.cs
- SharedPersonalizationStateInfo.cs
- ViewStateModeByIdAttribute.cs
- FileDialog_Vista_Interop.cs
- DirectionalLight.cs
- PageThemeCodeDomTreeGenerator.cs
- HttpInputStream.cs
- Stacktrace.cs
- DataGridTextBoxColumn.cs
- MultiBindingExpression.cs
- FieldTemplateUserControl.cs
- DiscoveryDocument.cs
- SystemIPInterfaceProperties.cs
- mactripleDES.cs
- SystemTcpStatistics.cs
- PassportAuthenticationEventArgs.cs
- WriteTimeStream.cs
- EmptyEnumerator.cs
- WebSysDescriptionAttribute.cs
- EnvelopedSignatureTransform.cs
- PermissionToken.cs
- AmbientValueAttribute.cs
- ReverseInheritProperty.cs
- GridPattern.cs
- KeySpline.cs
- DataGridViewAutoSizeModeEventArgs.cs
- UserControlAutomationPeer.cs
- ManipulationInertiaStartingEventArgs.cs
- WindowsListViewItemStartMenu.cs
- MD5CryptoServiceProvider.cs
- ArgumentException.cs
- ImageAttributes.cs
- Int32Storage.cs
- PointAnimationBase.cs
- CodeTypeOfExpression.cs
- Queue.cs
- CreateSequence.cs
- EFAssociationProvider.cs
- ListChangedEventArgs.cs
- GridViewDeleteEventArgs.cs
- DragDeltaEventArgs.cs
- ProfilePropertySettings.cs
- XmlSchemaException.cs
- DataTableClearEvent.cs
- State.cs
- ContextStaticAttribute.cs
- UserControlParser.cs
- BaseContextMenu.cs
- TreeViewHitTestInfo.cs
- Content.cs
- FileChangesMonitor.cs
- FormViewModeEventArgs.cs
- safex509handles.cs
- SqlTypeConverter.cs
- OLEDB_Enum.cs
- LostFocusEventManager.cs
- AttachmentService.cs
- RecordsAffectedEventArgs.cs
- DragDrop.cs
- DesignerForm.cs
- EnvironmentPermission.cs
- SessionPageStateSection.cs
- Matrix3DStack.cs
- EntitySetBaseCollection.cs