Code:
/ 4.0 / 4.0 / untmp / 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DynamicMetaObjectBinder.cs
- XhtmlBasicPageAdapter.cs
- LookupNode.cs
- PolyBezierSegment.cs
- WindowsEditBoxRange.cs
- DescendantQuery.cs
- precedingquery.cs
- ProtocolsSection.cs
- COM2ExtendedUITypeEditor.cs
- DbTransaction.cs
- EmbeddedObject.cs
- ExpressionList.cs
- SEHException.cs
- _LocalDataStoreMgr.cs
- EventProxy.cs
- SqlProvider.cs
- ResourceReferenceKeyNotFoundException.cs
- SchemaNamespaceManager.cs
- ContainerUtilities.cs
- RadioButtonPopupAdapter.cs
- HttpHandlerAction.cs
- SystemParameters.cs
- StreamAsIStream.cs
- ToolStripPanelRenderEventArgs.cs
- ModulesEntry.cs
- SQLUtility.cs
- FixedSOMTextRun.cs
- SafeRightsManagementEnvironmentHandle.cs
- EntityWrapperFactory.cs
- CurrentTimeZone.cs
- MessageQueueTransaction.cs
- DataControlFieldCell.cs
- COAUTHIDENTITY.cs
- FixedSOMPageConstructor.cs
- RouteItem.cs
- XmlLangPropertyAttribute.cs
- GenericNameHandler.cs
- WebPartConnectionsCancelEventArgs.cs
- Calendar.cs
- UnmanagedMemoryStream.cs
- FormViewDeleteEventArgs.cs
- SchemaImporterExtension.cs
- UnsafeNativeMethods.cs
- EntityFunctions.cs
- ObjectDataSource.cs
- OutputScopeManager.cs
- Int64AnimationUsingKeyFrames.cs
- Interlocked.cs
- UpdatePanelTrigger.cs
- InstanceStore.cs
- D3DImage.cs
- DataGridViewRowsRemovedEventArgs.cs
- RegexWorker.cs
- MenuItemBindingCollection.cs
- WindowsContainer.cs
- ConstructorArgumentAttribute.cs
- WebPartMenu.cs
- OdbcConnectionString.cs
- LinearGradientBrush.cs
- BlurEffect.cs
- Misc.cs
- VarInfo.cs
- NamespaceMapping.cs
- FileRecordSequenceHelper.cs
- MediaSystem.cs
- DataShape.cs
- CorrelationTokenInvalidatedHandler.cs
- RegionIterator.cs
- DbConnectionStringCommon.cs
- XmlSigningNodeWriter.cs
- CompileLiteralTextParser.cs
- KeyedCollection.cs
- BigInt.cs
- AssertSection.cs
- RequestResizeEvent.cs
- ExpressionEvaluator.cs
- LocationSectionRecord.cs
- DebugViewWriter.cs
- NumericUpDownAccelerationCollection.cs
- WindowCollection.cs
- _ProxyRegBlob.cs
- NumericUpDown.cs
- MethodExpr.cs
- ReflectionTypeLoadException.cs
- ValidatingReaderNodeData.cs
- ReachFixedPageSerializer.cs
- SecUtil.cs
- CheckBox.cs
- XmlElementList.cs
- ServiceInfo.cs
- RunWorkerCompletedEventArgs.cs
- WebPartEditVerb.cs
- ContextCorrelationInitializer.cs
- HttpVersion.cs
- VirtualPathProvider.cs
- MailAddress.cs
- SQLGuid.cs
- InvalidEnumArgumentException.cs
- HtmlWindow.cs
- Repeater.cs