Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / 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
- DateTimeAutomationPeer.cs
- CompositeScriptReference.cs
- XmlToDatasetMap.cs
- TextSegment.cs
- XmlQualifiedName.cs
- COM2Properties.cs
- UntypedNullExpression.cs
- MobileUITypeEditor.cs
- TemplateBaseAction.cs
- EnumValidator.cs
- ListItemCollection.cs
- SpoolingTask.cs
- Int64.cs
- AnonymousIdentificationSection.cs
- ConfigurationValues.cs
- WindowsTreeView.cs
- ISFTagAndGuidCache.cs
- ObjectSet.cs
- BinaryObjectReader.cs
- StateFinalizationActivity.cs
- ObjectFactoryCodeDomTreeGenerator.cs
- BinaryWriter.cs
- AnnotationStore.cs
- IgnoreFileBuildProvider.cs
- TemplatedWizardStep.cs
- WebAdminConfigurationHelper.cs
- CryptoHandle.cs
- ZipPackagePart.cs
- DocumentViewerConstants.cs
- CodeCommentStatementCollection.cs
- HtmlDocument.cs
- ObjectStateManager.cs
- ContractMethodInfo.cs
- Pen.cs
- DelegatingHeader.cs
- TrackingMemoryStreamFactory.cs
- UnitySerializationHolder.cs
- DataGridViewColumnEventArgs.cs
- TextBoxDesigner.cs
- PerfCounters.cs
- DemultiplexingDispatchMessageFormatter.cs
- HtmlInputCheckBox.cs
- ZoneLinkButton.cs
- WindowInteractionStateTracker.cs
- CultureSpecificStringDictionary.cs
- StreamGeometryContext.cs
- ContainerTracking.cs
- EditorPartChrome.cs
- PackagingUtilities.cs
- PathSegmentCollection.cs
- MethodExpr.cs
- EmptyElement.cs
- ConversionHelper.cs
- StorageFunctionMapping.cs
- SqlNotificationRequest.cs
- BindingsCollection.cs
- GenericParameterDataContract.cs
- KeyboardDevice.cs
- XmlSchemaDatatype.cs
- ProjectionRewriter.cs
- _LoggingObject.cs
- TreeNodeCollection.cs
- TextEditorCharacters.cs
- AdornerLayer.cs
- EntityCommandExecutionException.cs
- FontFamilyIdentifier.cs
- FunctionMappingTranslator.cs
- InkCanvasInnerCanvas.cs
- OutputCacheProfile.cs
- SymLanguageType.cs
- SqlConnectionHelper.cs
- ImageSource.cs
- PagesChangedEventArgs.cs
- ServiceTimeoutsElement.cs
- WorkflowMessageEventHandler.cs
- SQLGuidStorage.cs
- SqlFlattener.cs
- DockPatternIdentifiers.cs
- RadioButton.cs
- WorkItem.cs
- DataTableReader.cs
- handlecollector.cs
- PartialTrustValidationBehavior.cs
- MessageBox.cs
- PageContentAsyncResult.cs
- TextTreeExtractElementUndoUnit.cs
- MergeFilterQuery.cs
- EncryptedType.cs
- CodeCatchClauseCollection.cs
- XmlDesigner.cs
- SoapExtensionStream.cs
- EventLogPermissionEntryCollection.cs
- SessionPageStatePersister.cs
- AuthenticationSection.cs
- MergeFilterQuery.cs
- CodeChecksumPragma.cs
- RtfToken.cs
- PcmConverter.cs
- XmlStreamStore.cs
- TableStyle.cs