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; ////// /// 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 { 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
- MailSettingsSection.cs
- StorageTypeMapping.cs
- Enlistment.cs
- HierarchicalDataBoundControl.cs
- HashUtility.cs
- BrowserDefinitionCollection.cs
- MobileUserControlDesigner.cs
- GenericXmlSecurityTokenAuthenticator.cs
- SourceFileInfo.cs
- TabItem.cs
- ListViewUpdatedEventArgs.cs
- EntitySetDataBindingList.cs
- DetailsViewRowCollection.cs
- WebPartHelpVerb.cs
- ObjectReaderCompiler.cs
- WebRequestModuleElementCollection.cs
- KeyToListMap.cs
- DBNull.cs
- CleanUpVirtualizedItemEventArgs.cs
- QilGenerator.cs
- METAHEADER.cs
- SqlXml.cs
- ParameterCollectionEditor.cs
- ProviderCollection.cs
- MsmqEncryptionAlgorithm.cs
- StyleSheet.cs
- LinearGradientBrush.cs
- TabletCollection.cs
- ThreadExceptionEvent.cs
- MsmqActivation.cs
- TargetFrameworkAttribute.cs
- BaseCodeDomTreeGenerator.cs
- InstanceDescriptor.cs
- ConfigurationStrings.cs
- ClassHandlersStore.cs
- HierarchicalDataBoundControl.cs
- AuthenticationService.cs
- Menu.cs
- IFlowDocumentViewer.cs
- WebProxyScriptElement.cs
- StaticExtension.cs
- CroppedBitmap.cs
- Operand.cs
- TcpProcessProtocolHandler.cs
- TransportContext.cs
- StateWorkerRequest.cs
- XmlImplementation.cs
- SettingsBindableAttribute.cs
- TextModifierScope.cs
- Brush.cs
- XmlNodeReader.cs
- PagesChangedEventArgs.cs
- OdbcReferenceCollection.cs
- DecimalStorage.cs
- CreateSequenceResponse.cs
- EdmRelationshipRoleAttribute.cs
- EnumType.cs
- OleDbCommand.cs
- DataGridViewElement.cs
- IPEndPoint.cs
- ImageField.cs
- MetadataPropertyCollection.cs
- MemberDescriptor.cs
- SchemaImporterExtensionElement.cs
- TempFiles.cs
- DataObjectSettingDataEventArgs.cs
- EventItfInfo.cs
- ConfigurationHandlersInstallComponent.cs
- XslCompiledTransform.cs
- AuthenticationModulesSection.cs
- CapacityStreamGeometryContext.cs
- util.cs
- SqlFileStream.cs
- ContractMethodInfo.cs
- DefinitionBase.cs
- ListViewSelectEventArgs.cs
- BamlRecordReader.cs
- HttpHandlersSection.cs
- VisualCollection.cs
- PropertyOrder.cs
- RunClient.cs
- ExpandableObjectConverter.cs
- CompiledRegexRunnerFactory.cs
- NoResizeSelectionBorderGlyph.cs
- SingleTagSectionHandler.cs
- HttpListenerResponse.cs
- MetadataUtilsSmi.cs
- InkPresenterAutomationPeer.cs
- ComponentCollection.cs
- ThousandthOfEmRealPoints.cs
- StylusTip.cs
- KeyedCollection.cs
- NetTcpSecurity.cs
- InternalConfigHost.cs
- XamlVector3DCollectionSerializer.cs
- SoapIgnoreAttribute.cs
- SyndicationDeserializer.cs
- ListManagerBindingsCollection.cs
- CommandPlan.cs
- ButtonBase.cs