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;
///
///
/// Retrives the printer graphics during preview.
///
internal class PrintPreviewGraphics {
private PrintPageEventArgs printPageEventArgs;
private PrintDocument printDocument;
public PrintPreviewGraphics(PrintDocument document, PrintPageEventArgs e) {
printPageEventArgs = e;
printDocument = document;
}
///
///
/// 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
- TextElementEnumerator.cs
- ObjectAssociationEndMapping.cs
- ResourcePool.cs
- FilterElement.cs
- WindowsScrollBarBits.cs
- Binding.cs
- ZipIOCentralDirectoryBlock.cs
- WpfWebRequestHelper.cs
- TextTreeDeleteContentUndoUnit.cs
- BuildProviderUtils.cs
- ToolBarButtonDesigner.cs
- Pair.cs
- PathFigureCollectionConverter.cs
- XmlArrayItemAttribute.cs
- DetailsView.cs
- SessionPageStateSection.cs
- PostBackOptions.cs
- LocalIdCollection.cs
- LabelLiteral.cs
- DefaultHttpHandler.cs
- PropertyTabAttribute.cs
- XmlDataSource.cs
- SymbolEqualComparer.cs
- AuthenticationModuleElementCollection.cs
- Query.cs
- LogicalExpr.cs
- ConditionValidator.cs
- ScrollChrome.cs
- VectorConverter.cs
- PartialCachingAttribute.cs
- HttpCacheVaryByContentEncodings.cs
- Adorner.cs
- PhonemeConverter.cs
- FileDataSourceCache.cs
- CheckBoxStandardAdapter.cs
- DataGridViewCellStyleChangedEventArgs.cs
- ModuleElement.cs
- EncryptedPackage.cs
- TreeNodeBindingCollection.cs
- XmlIterators.cs
- FilterQueryOptionExpression.cs
- ExpressionWriter.cs
- ToolStripCodeDomSerializer.cs
- MetadataArtifactLoaderCompositeResource.cs
- PreviewControlDesigner.cs
- DefaultWorkflowSchedulerService.cs
- ScriptingSectionGroup.cs
- WebConfigurationManager.cs
- UnsafeNativeMethods.cs
- UrlParameterWriter.cs
- RegistryPermission.cs
- ListControlDesigner.cs
- DateTimeValueSerializerContext.cs
- StylusDevice.cs
- ToolZone.cs
- UIntPtr.cs
- HtmlHead.cs
- ipaddressinformationcollection.cs
- FileFormatException.cs
- SafePointer.cs
- RuntimeHandles.cs
- ClientOperationFormatterProvider.cs
- MailMessageEventArgs.cs
- UntrustedRecipientException.cs
- BrowsableAttribute.cs
- StateInitialization.cs
- SemanticResultValue.cs
- ProofTokenCryptoHandle.cs
- ImageDrawing.cs
- ServiceDescription.cs
- AnnotationService.cs
- OrderByLifter.cs
- XmlFormatWriterGenerator.cs
- NCryptSafeHandles.cs
- SafeCryptoHandles.cs
- Timer.cs
- WindowsUpDown.cs
- XPathNodeIterator.cs
- RC2CryptoServiceProvider.cs
- Math.cs
- CellParaClient.cs
- LoginViewDesigner.cs
- Stylesheet.cs
- COM2ComponentEditor.cs
- IdentityHolder.cs
- HttpServerUtilityBase.cs
- SecurityStateEncoder.cs
- ObjectDataSourceEventArgs.cs
- SafeTokenHandle.cs
- TextModifierScope.cs
- XPathSingletonIterator.cs
- EUCJPEncoding.cs
- SrgsRulesCollection.cs
- XsdDateTime.cs
- Stroke2.cs
- SystemNetHelpers.cs
- DataGridViewComboBoxColumn.cs
- VisualStateGroup.cs
- FormsAuthenticationConfiguration.cs
- UserControlAutomationPeer.cs