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
- ParserOptions.cs
- DataGridViewButtonColumn.cs
- StandardCommands.cs
- SqlClientFactory.cs
- TextBox.cs
- TextTreeNode.cs
- GC.cs
- xamlnodes.cs
- DetailsViewInsertEventArgs.cs
- IsolatedStorage.cs
- SupportsPreviewControlAttribute.cs
- ScaleTransform.cs
- TargetParameterCountException.cs
- XmlElementAttributes.cs
- OutputCacheProviderCollection.cs
- SocketStream.cs
- XMLUtil.cs
- BookmarkEventArgs.cs
- BrowserDefinitionCollection.cs
- EnterpriseServicesHelper.cs
- complextypematerializer.cs
- AccessDataSourceView.cs
- PropertyHelper.cs
- DocumentViewerBase.cs
- ThreadStateException.cs
- XmlEventCache.cs
- WindowsStatusBar.cs
- ZipIOLocalFileHeader.cs
- MultiView.cs
- CharacterString.cs
- WarningException.cs
- TransactedReceiveScope.cs
- _FixedSizeReader.cs
- PlanCompiler.cs
- XmlTextReader.cs
- VersionPair.cs
- UpdateTracker.cs
- TCPListener.cs
- BackgroundFormatInfo.cs
- MergeExecutor.cs
- __Filters.cs
- Odbc32.cs
- DataSysAttribute.cs
- CounterSetInstanceCounterDataSet.cs
- CodeCastExpression.cs
- SqlErrorCollection.cs
- CryptoHandle.cs
- autovalidator.cs
- BinHexEncoder.cs
- WorkflowRuntimeServiceElement.cs
- WindowVisualStateTracker.cs
- DrawingVisual.cs
- DtdParser.cs
- XmlLoader.cs
- RemotingConfiguration.cs
- AspNetHostingPermission.cs
- ApplyTemplatesAction.cs
- HttpContextServiceHost.cs
- RequestContextBase.cs
- Parsers.cs
- EnumUnknown.cs
- XmlDictionary.cs
- ContextStaticAttribute.cs
- PeerInvitationResponse.cs
- ObservableCollection.cs
- WebScriptEndpointElement.cs
- ISFClipboardData.cs
- SmtpReplyReaderFactory.cs
- ToolStripOverflowButton.cs
- RepeaterItemEventArgs.cs
- QuaternionRotation3D.cs
- DetailsViewUpdatedEventArgs.cs
- ControlBuilder.cs
- Mutex.cs
- TextSchema.cs
- ResourceProviderFactory.cs
- Typeface.cs
- ContentPlaceHolder.cs
- DifferencingCollection.cs
- ProcessManager.cs
- CqlErrorHelper.cs
- FreezableCollection.cs
- FlowDocumentScrollViewerAutomationPeer.cs
- SBCSCodePageEncoding.cs
- TreeView.cs
- DataGridTextBox.cs
- StickyNoteContentControl.cs
- XsdDuration.cs
- ApplicationServiceManager.cs
- DbQueryCommandTree.cs
- XmlUrlEditor.cs
- XmlName.cs
- SqlRowUpdatedEvent.cs
- RemoteCryptoSignHashRequest.cs
- Ray3DHitTestResult.cs
- LocalizationParserHooks.cs
- StandardBindingReliableSessionElement.cs
- FixedSOMLineCollection.cs
- CalendarButtonAutomationPeer.cs
- Thumb.cs