Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- XamlStream.cs
- Material.cs
- EntityWithChangeTrackerStrategy.cs
- ButtonField.cs
- ImmComposition.cs
- FieldNameLookup.cs
- UdpReplyToBehavior.cs
- FormatConvertedBitmap.cs
- SafeMILHandle.cs
- Stylus.cs
- ExpressionBindingCollection.cs
- BamlBinaryWriter.cs
- Rights.cs
- ListChangedEventArgs.cs
- SafeFileHandle.cs
- LicenseManager.cs
- DocumentViewer.cs
- ExpressionPrinter.cs
- ButtonColumn.cs
- OrderedDictionary.cs
- MDIWindowDialog.cs
- Listbox.cs
- ComplexBindingPropertiesAttribute.cs
- XmlSchemaAnnotation.cs
- RowsCopiedEventArgs.cs
- util.cs
- ADRoleFactory.cs
- parserscommon.cs
- DataTableTypeConverter.cs
- MarkupExtensionSerializer.cs
- ImageListUtils.cs
- TrackingConditionCollection.cs
- EventTrigger.cs
- IconBitmapDecoder.cs
- TextElementEditingBehaviorAttribute.cs
- FullTextBreakpoint.cs
- BamlBinaryReader.cs
- PrefixQName.cs
- CommandBinding.cs
- ApplicationDirectory.cs
- CollectionViewGroupRoot.cs
- HybridDictionary.cs
- DrawingGroup.cs
- JavascriptCallbackResponseProperty.cs
- MethodAccessException.cs
- InvalidCommandTreeException.cs
- TypeUnloadedException.cs
- SingleAnimationBase.cs
- SuppressIldasmAttribute.cs
- PerfCounters.cs
- LineGeometry.cs
- CoordinationService.cs
- EndpointAddress10.cs
- ThreadAbortException.cs
- SoapReflector.cs
- X509SecurityToken.cs
- CancelRequestedRecord.cs
- _ChunkParse.cs
- SiteMapNodeItemEventArgs.cs
- WindowClosedEventArgs.cs
- PrimarySelectionAdorner.cs
- ValidationService.cs
- DispatcherHookEventArgs.cs
- Icon.cs
- AssemblyBuilderData.cs
- RelationshipDetailsRow.cs
- RestHandler.cs
- ReadContentAsBinaryHelper.cs
- SwitchLevelAttribute.cs
- WebPartConnectionsConnectVerb.cs
- Transform.cs
- Variable.cs
- Grid.cs
- DataBindingList.cs
- BuildProviderAppliesToAttribute.cs
- StructuralComparisons.cs
- WebBrowserPermission.cs
- TypeConverterHelper.cs
- ConfigurationPropertyAttribute.cs
- MemoryMappedFileSecurity.cs
- ConfigsHelper.cs
- CodeVariableDeclarationStatement.cs
- CatalogPartDesigner.cs
- LayoutExceptionEventArgs.cs
- ThreadAbortException.cs
- TreeWalkHelper.cs
- TrackingParticipant.cs
- Rotation3D.cs
- DeviceContext.cs
- ColumnMapVisitor.cs
- QilBinary.cs
- ProcessThreadDesigner.cs
- InfiniteTimeSpanConverter.cs
- EqualityArray.cs
- LinearQuaternionKeyFrame.cs
- DefaultHttpHandler.cs
- xdrvalidator.cs
- LogicalCallContext.cs
- CapabilitiesState.cs
- MetaModel.cs