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; ////// /// 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
- ComponentFactoryHelpers.cs
- EntityDataSourceContextCreatingEventArgs.cs
- TypeUtils.cs
- TypedElement.cs
- TableItemStyle.cs
- RsaKeyIdentifierClause.cs
- dbdatarecord.cs
- TraceHandlerErrorFormatter.cs
- Soap12ProtocolImporter.cs
- CalendarTable.cs
- UnauthorizedAccessException.cs
- WebServiceMethodData.cs
- PackageRelationshipSelector.cs
- OperationResponse.cs
- FieldNameLookup.cs
- HandledEventArgs.cs
- CreateInstanceBinder.cs
- BreakRecordTable.cs
- StateMachineSubscriptionManager.cs
- ControlAdapter.cs
- ColorConverter.cs
- RenamedEventArgs.cs
- TextServicesManager.cs
- SortFieldComparer.cs
- EncryptedData.cs
- TextTreeTextNode.cs
- TextTreeInsertElementUndoUnit.cs
- DataStreamFromComStream.cs
- WebPartTransformerCollection.cs
- StrokeCollection2.cs
- TreeView.cs
- MemberRelationshipService.cs
- DiagnosticsElement.cs
- PropertyTab.cs
- Location.cs
- SectionVisual.cs
- IxmlLineInfo.cs
- AnnotationAuthorChangedEventArgs.cs
- ColorTranslator.cs
- CheckBoxAutomationPeer.cs
- SpoolingTask.cs
- SmiEventStream.cs
- ProcessProtocolHandler.cs
- messageonlyhwndwrapper.cs
- Subset.cs
- ToolStripComboBox.cs
- ExtenderControl.cs
- SafeUserTokenHandle.cs
- XmlSignatureManifest.cs
- UniqueCodeIdentifierScope.cs
- NetworkInterface.cs
- StatusStrip.cs
- WebPartZone.cs
- precedingquery.cs
- ObjectComplexPropertyMapping.cs
- Empty.cs
- TemplateManager.cs
- StrokeCollectionDefaultValueFactory.cs
- HttpRawResponse.cs
- ReadOnlyCollectionBuilder.cs
- RecognizedPhrase.cs
- UidPropertyAttribute.cs
- ImageListUtils.cs
- wmiutil.cs
- ManagementEventArgs.cs
- BindingExpressionBase.cs
- AutomationPeer.cs
- TextSelection.cs
- ZipIOExtraFieldPaddingElement.cs
- XmlArrayAttribute.cs
- PriorityBindingExpression.cs
- LookupNode.cs
- PerformanceCounterManager.cs
- ValidatingReaderNodeData.cs
- ImageInfo.cs
- TryCatch.cs
- CodePropertyReferenceExpression.cs
- GridEntryCollection.cs
- Certificate.cs
- NamespaceCollection.cs
- TrackingProfileSerializer.cs
- DataGridViewRowDividerDoubleClickEventArgs.cs
- DatagridviewDisplayedBandsData.cs
- Focus.cs
- StreamedWorkflowDefinitionContext.cs
- ContractMethodInfo.cs
- SubstitutionDesigner.cs
- XslTransform.cs
- Expression.cs
- TypeRefElement.cs
- EngineSiteSapi.cs
- RelativeSource.cs
- WebPartConnectVerb.cs
- BufferedWebEventProvider.cs
- PropertyOverridesTypeEditor.cs
- WindowsContainer.cs
- autovalidator.cs
- BooleanExpr.cs
- DataGridViewHeaderCell.cs
- MemoryRecordBuffer.cs