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
- DSASignatureDeformatter.cs
- Geometry3D.cs
- DataGridViewSelectedCellCollection.cs
- ExpanderAutomationPeer.cs
- DesignerMetadata.cs
- PauseStoryboard.cs
- HttpRequest.cs
- DataGridViewTextBoxEditingControl.cs
- PlainXmlSerializer.cs
- Opcode.cs
- IPGlobalProperties.cs
- ColumnCollection.cs
- XmlSchemaAnyAttribute.cs
- WindowsListViewItemCheckBox.cs
- ObjectDataSourceStatusEventArgs.cs
- ResourceExpressionEditorSheet.cs
- UntrustedRecipientException.cs
- XmlSchemaAttributeGroupRef.cs
- CharacterShapingProperties.cs
- StorageRoot.cs
- ListViewSortEventArgs.cs
- XmlSchemaSimpleTypeRestriction.cs
- IdentitySection.cs
- AppSecurityManager.cs
- UserControlParser.cs
- WebBaseEventKeyComparer.cs
- OdbcTransaction.cs
- FileLevelControlBuilderAttribute.cs
- IndexedString.cs
- Frame.cs
- MetadataItemEmitter.cs
- SmtpTransport.cs
- XsltException.cs
- StylusTouchDevice.cs
- AvTraceDetails.cs
- UpDownEvent.cs
- AutoSizeComboBox.cs
- ProtocolsConfiguration.cs
- ImageInfo.cs
- WebHttpBindingCollectionElement.cs
- ParsedAttributeCollection.cs
- Geometry.cs
- DataGridViewCell.cs
- DocumentEventArgs.cs
- XmlWriterTraceListener.cs
- ClientTargetSection.cs
- uribuilder.cs
- TraceSource.cs
- CodeArgumentReferenceExpression.cs
- DefaultSection.cs
- EntityContainer.cs
- BaseCollection.cs
- ZipPackagePart.cs
- MenuItemStyleCollection.cs
- CollectionConverter.cs
- SSmlParser.cs
- SiteMapNodeItemEventArgs.cs
- IndexedString.cs
- OleDbTransaction.cs
- ArgumentOutOfRangeException.cs
- AxisAngleRotation3D.cs
- SafeProcessHandle.cs
- SQLMoney.cs
- AccessViolationException.cs
- Vector3DKeyFrameCollection.cs
- CharacterHit.cs
- DataQuery.cs
- CLSCompliantAttribute.cs
- HttpPostClientProtocol.cs
- WSDualHttpBindingCollectionElement.cs
- SourceInterpreter.cs
- HealthMonitoringSection.cs
- SqlDataSourceFilteringEventArgs.cs
- DrawingAttributeSerializer.cs
- TransformDescriptor.cs
- InheritedPropertyChangedEventArgs.cs
- _NestedMultipleAsyncResult.cs
- PackageDigitalSignature.cs
- KnownTypes.cs
- MethodBody.cs
- RefreshEventArgs.cs
- ObjectStateEntryDbUpdatableDataRecord.cs
- SemanticResolver.cs
- AssemblyBuilder.cs
- AutomationProperties.cs
- AttachedPropertyBrowsableForChildrenAttribute.cs
- TreeViewTemplateSelector.cs
- ReadOnlyObservableCollection.cs
- Predicate.cs
- GlyphRunDrawing.cs
- DeviceFilterDictionary.cs
- DWriteFactory.cs
- ByteStack.cs
- Bits.cs
- UnsignedPublishLicense.cs
- Bits.cs
- EntityReference.cs
- FunctionParameter.cs
- CardSpaceException.cs
- SQLDecimal.cs