Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / 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
- _BasicClient.cs
- AuthorizationRuleCollection.cs
- AbsoluteQuery.cs
- TraceProvider.cs
- Lock.cs
- XamlNamespaceHelper.cs
- DataStreams.cs
- ListCollectionView.cs
- HuffCodec.cs
- PointCollectionValueSerializer.cs
- XmlILModule.cs
- UrlPath.cs
- SectionXmlInfo.cs
- DigitalSignatureProvider.cs
- MetadataSource.cs
- TextParentUndoUnit.cs
- BindValidator.cs
- ArgumentOutOfRangeException.cs
- NativeMethods.cs
- PrintDialogException.cs
- Slider.cs
- BitmapFrame.cs
- HtmlControl.cs
- PnrpPermission.cs
- UIElement3D.cs
- XPathSelectionIterator.cs
- SchemaSetCompiler.cs
- ObjectDataSourceSelectingEventArgs.cs
- SqlLiftWhereClauses.cs
- DelegatingTypeDescriptionProvider.cs
- Regex.cs
- EntityDataSourceWrapperPropertyDescriptor.cs
- ContextStack.cs
- ExpressionList.cs
- KeyProperty.cs
- COSERVERINFO.cs
- TypeSystem.cs
- SQLCharsStorage.cs
- SerializationFieldInfo.cs
- MsmqIntegrationElement.cs
- RoleBoolean.cs
- PageAsyncTask.cs
- DependencyPropertyDescriptor.cs
- CheckBoxBaseAdapter.cs
- TypeElementCollection.cs
- TextSegment.cs
- StagingAreaInputItem.cs
- EdgeModeValidation.cs
- OdbcConnectionStringbuilder.cs
- DataBoundControlHelper.cs
- TextRangeEditLists.cs
- ConfigXmlComment.cs
- ResizeBehavior.cs
- TemplateBamlTreeBuilder.cs
- CodeExporter.cs
- SchemaCollectionCompiler.cs
- PackWebResponse.cs
- FilterRepeater.cs
- SymLanguageType.cs
- CodeRegionDirective.cs
- UniformGrid.cs
- ContextTokenTypeConverter.cs
- SafeNativeMethods.cs
- NetworkAddressChange.cs
- CopyCodeAction.cs
- ErrorWrapper.cs
- AttributeUsageAttribute.cs
- BCLDebug.cs
- DesignerDataStoredProcedure.cs
- StructuralObject.cs
- XmlUtf8RawTextWriter.cs
- BaseDataListDesigner.cs
- ListView.cs
- Rect3D.cs
- SafeReadContext.cs
- PersonalizablePropertyEntry.cs
- QilExpression.cs
- TimeoutHelper.cs
- MimeMultiPart.cs
- TableLayoutPanel.cs
- UpdateException.cs
- PrintPreviewControl.cs
- CodeDelegateInvokeExpression.cs
- RangeBase.cs
- SelectionPattern.cs
- HashHelper.cs
- DocumentPaginator.cs
- PerfCounters.cs
- DPCustomTypeDescriptor.cs
- SQLGuid.cs
- DataTableReaderListener.cs
- Events.cs
- KeyManager.cs
- SqlConnectionPoolGroupProviderInfo.cs
- XmlLanguage.cs
- tooltip.cs
- LayoutSettings.cs
- RecognizerBase.cs
- SHA1.cs
- ZipIOEndOfCentralDirectoryBlock.cs