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
- SqlBuilder.cs
- TypeContext.cs
- ListMarkerSourceInfo.cs
- ValidationSummary.cs
- RectValueSerializer.cs
- ClientScriptManagerWrapper.cs
- HttpContext.cs
- Window.cs
- MetadataFile.cs
- WebPartDisplayMode.cs
- SafeHandle.cs
- DirtyTextRange.cs
- PageVisual.cs
- ErrorWrapper.cs
- SelectedCellsChangedEventArgs.cs
- DataRecordObjectView.cs
- SafeNativeMethods.cs
- CheckBoxField.cs
- ReferencedCollectionType.cs
- entitydatasourceentitysetnameconverter.cs
- BaseServiceProvider.cs
- HttpDictionary.cs
- ClientTargetSection.cs
- AnimationClockResource.cs
- ReadOnlyHierarchicalDataSource.cs
- WizardStepBase.cs
- VersionedStreamOwner.cs
- EntityContainerAssociationSetEnd.cs
- GridViewEditEventArgs.cs
- StringHandle.cs
- EntityDataSourceQueryBuilder.cs
- FragmentQuery.cs
- ExpressionVisitor.cs
- assertwrapper.cs
- WindowsSpinner.cs
- XmlSchemaGroupRef.cs
- WebServiceFaultDesigner.cs
- RuntimeHelpers.cs
- NullableConverter.cs
- BindToObject.cs
- GridEntryCollection.cs
- ViewCellSlot.cs
- SqlBinder.cs
- ScriptManager.cs
- XmlWriterTraceListener.cs
- CannotUnloadAppDomainException.cs
- PersistenceProviderDirectory.cs
- ListDictionary.cs
- DataViewManager.cs
- CompensationTokenData.cs
- FastEncoderWindow.cs
- Automation.cs
- OpenTypeLayoutCache.cs
- CompressedStack.cs
- TimeZone.cs
- Point3DConverter.cs
- PrintPreviewDialog.cs
- XmlUtil.cs
- LocatorPartList.cs
- FixedPageProcessor.cs
- CommonDialog.cs
- SystemTcpConnection.cs
- LifetimeServices.cs
- CustomAssemblyResolver.cs
- TextServicesLoader.cs
- WindowsGraphicsWrapper.cs
- SimpleExpression.cs
- TextSelectionProcessor.cs
- WindowsProgressbar.cs
- Memoizer.cs
- PackageRelationship.cs
- PolicyDesigner.cs
- CapabilitiesState.cs
- NullableLongMinMaxAggregationOperator.cs
- CustomSignedXml.cs
- ExpressionBuilder.cs
- Bits.cs
- OptimalTextSource.cs
- ListViewInsertEventArgs.cs
- SqlClientMetaDataCollectionNames.cs
- FontEditor.cs
- RuntimeCompatibilityAttribute.cs
- FontTypeConverter.cs
- WorkingDirectoryEditor.cs
- HelloOperationAsyncResult.cs
- FieldNameLookup.cs
- HandleCollector.cs
- XmlQueryOutput.cs
- OperationResponse.cs
- AnchoredBlock.cs
- IPAddress.cs
- Parser.cs
- NativeMethods.cs
- DelegatedStream.cs
- altserialization.cs
- xmlformatgeneratorstatics.cs
- SR.Designer.cs
- FileRecordSequenceCompletedAsyncResult.cs
- SQLChars.cs
- Memoizer.cs