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;
///
///
/// 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 {
[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
- MemberProjectionIndex.cs
- SocketInformation.cs
- OracleParameterCollection.cs
- Literal.cs
- OwnerDrawPropertyBag.cs
- GradientStop.cs
- BuildProviderUtils.cs
- AllMembershipCondition.cs
- Rights.cs
- CodeTypeParameter.cs
- TripleDES.cs
- CreateRefExpr.cs
- WebBaseEventKeyComparer.cs
- MsmqIntegrationElement.cs
- parserscommon.cs
- LayoutEditorPart.cs
- GradientSpreadMethodValidation.cs
- XmlExpressionDumper.cs
- Rotation3DAnimation.cs
- HttpServerVarsCollection.cs
- EventlogProvider.cs
- Matrix3DConverter.cs
- cookiecollection.cs
- ComboBox.cs
- DBSchemaTable.cs
- EventLogEntry.cs
- BitmapEffectState.cs
- CustomWebEventKey.cs
- GZipStream.cs
- ChooseAction.cs
- RadioButtonBaseAdapter.cs
- GeometryDrawing.cs
- PhysicalAddress.cs
- NCryptSafeHandles.cs
- Button.cs
- PropertyEmitter.cs
- AdjustableArrowCap.cs
- NetNamedPipeSecurity.cs
- UrlMappingsSection.cs
- XXXOnTypeBuilderInstantiation.cs
- ColorConverter.cs
- CachedFontFamily.cs
- ToolStripDropDownMenu.cs
- ReaderWriterLock.cs
- IriParsingElement.cs
- SessionStateItemCollection.cs
- MediaCommands.cs
- Composition.cs
- EntityDataSourceWrapper.cs
- FigureParaClient.cs
- CodePropertyReferenceExpression.cs
- Pkcs7Recipient.cs
- CellTreeNode.cs
- FrugalMap.cs
- SQLByte.cs
- ColumnClickEvent.cs
- CssStyleCollection.cs
- DataBoundControlAdapter.cs
- infer.cs
- HttpListener.cs
- StatusBar.cs
- TextReader.cs
- OutputWindow.cs
- SimpleHandlerBuildProvider.cs
- path.cs
- GcSettings.cs
- DiscardableAttribute.cs
- PathData.cs
- IPGlobalProperties.cs
- QuaternionConverter.cs
- ProfileParameter.cs
- HwndSourceParameters.cs
- AccessText.cs
- LocalBuilder.cs
- EntitySqlException.cs
- FixedSOMFixedBlock.cs
- Zone.cs
- XamlReader.cs
- Pen.cs
- EditorPartCollection.cs
- RangeContentEnumerator.cs
- CriticalFinalizerObject.cs
- StatusBar.cs
- XmlUtil.cs
- RotateTransform.cs
- ADMembershipProvider.cs
- RawStylusActions.cs
- CommandValueSerializer.cs
- SettingsContext.cs
- SingleObjectCollection.cs
- Visual3DCollection.cs
- BooleanFacetDescriptionElement.cs
- TouchEventArgs.cs
- AppDomainFactory.cs
- X509ChainElement.cs
- XmlFormatExtensionAttribute.cs
- SelectionItemPattern.cs
- HttpProfileBase.cs
- NameNode.cs
- ToolboxItemCollection.cs