Code:
/ DotNET / DotNET / 8.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
- SqlClientPermission.cs
- UIElementCollection.cs
- XmlDocument.cs
- CanExecuteRoutedEventArgs.cs
- TextComposition.cs
- StrongNameUtility.cs
- DynamicQueryStringParameter.cs
- ListViewSortEventArgs.cs
- DefaultEventAttribute.cs
- GenericEnumerator.cs
- SourceFileInfo.cs
- InstallerTypeAttribute.cs
- objectresult_tresulttype.cs
- HttpCookiesSection.cs
- ParenExpr.cs
- MemberCollection.cs
- AudioException.cs
- CheckBoxFlatAdapter.cs
- SeparatorAutomationPeer.cs
- RuleInfoComparer.cs
- StringCollection.cs
- WebBrowser.cs
- ControlCollection.cs
- DataGridViewTextBoxCell.cs
- DataViewSettingCollection.cs
- PartBasedPackageProperties.cs
- DescriptionAttribute.cs
- VectorAnimation.cs
- MetadataPropertyCollection.cs
- ObjectSet.cs
- DataGridViewControlCollection.cs
- xsdvalidator.cs
- GorillaCodec.cs
- BuildProvider.cs
- DataGridParentRows.cs
- JoinSymbol.cs
- HideDisabledControlAdapter.cs
- CmsInterop.cs
- ControlBuilderAttribute.cs
- InvalidAsynchronousStateException.cs
- ContextStaticAttribute.cs
- XmlQueryType.cs
- ResourceContainer.cs
- MimeXmlImporter.cs
- RemoteWebConfigurationHostServer.cs
- SchemaImporterExtensionElementCollection.cs
- CorrelationManager.cs
- BaseParser.cs
- AbandonedMutexException.cs
- PersonalizationState.cs
- DialogResultConverter.cs
- XPathAncestorIterator.cs
- FormDocumentDesigner.cs
- GCHandleCookieTable.cs
- XmlSchemaCompilationSettings.cs
- TextOptionsInternal.cs
- SamlAttributeStatement.cs
- SafeJobHandle.cs
- StylusPointPropertyId.cs
- ObjectReferenceStack.cs
- DataTrigger.cs
- PanelDesigner.cs
- Application.cs
- TextHintingModeValidation.cs
- FlagsAttribute.cs
- SocketSettings.cs
- GregorianCalendar.cs
- InternalConfigHost.cs
- ModelPropertyImpl.cs
- HtmlInputControl.cs
- CustomErrorsSectionWrapper.cs
- CompiledRegexRunnerFactory.cs
- BadImageFormatException.cs
- MediaPlayer.cs
- EventBuilder.cs
- RootBrowserWindowProxy.cs
- TokenFactoryBase.cs
- PassportAuthenticationModule.cs
- ConfigXmlComment.cs
- ClientConfigurationHost.cs
- BitmapData.cs
- EntityDataSourceView.cs
- WebRequestModuleElement.cs
- Identifier.cs
- CacheDependency.cs
- SHA256.cs
- tibetanshape.cs
- DataError.cs
- AttachedAnnotation.cs
- WsdlParser.cs
- TypeBuilder.cs
- COAUTHIDENTITY.cs
- ResourceIDHelper.cs
- IteratorDescriptor.cs
- EventToken.cs
- PreviewKeyDownEventArgs.cs
- TCEAdapterGenerator.cs
- ImplicitInputBrush.cs
- GeneralTransform3DCollection.cs
- MessageQueueTransaction.cs