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
- ApplicationSettingsBase.cs
- Bits.cs
- NavigatorInput.cs
- RoleService.cs
- FontEmbeddingManager.cs
- Style.cs
- FillBehavior.cs
- _SSPISessionCache.cs
- NumberSubstitution.cs
- InteropExecutor.cs
- CodeSnippetCompileUnit.cs
- ErrorCodes.cs
- _NestedMultipleAsyncResult.cs
- ContentOperations.cs
- KeyFrames.cs
- AnimationLayer.cs
- TemplateBuilder.cs
- StaticSiteMapProvider.cs
- AutomationAttributeInfo.cs
- DataControlFieldHeaderCell.cs
- EllipticalNodeOperations.cs
- EventLogPermissionEntryCollection.cs
- GlyphRun.cs
- BoolExpr.cs
- CommandEventArgs.cs
- Deserializer.cs
- SqlServices.cs
- RelatedCurrencyManager.cs
- DataSet.cs
- AsyncOperation.cs
- DocumentViewerHelper.cs
- TextDocumentView.cs
- SqlCharStream.cs
- TrustLevelCollection.cs
- MetadataUtil.cs
- SQLByteStorage.cs
- ValidationErrorCollection.cs
- unitconverter.cs
- TextComposition.cs
- CapabilitiesAssignment.cs
- GenericsInstances.cs
- Parallel.cs
- MergePropertyDescriptor.cs
- MetadataFile.cs
- ServiceNotStartedException.cs
- DataGridViewMethods.cs
- MetadataArtifactLoaderXmlReaderWrapper.cs
- DocumentReference.cs
- DbDataRecord.cs
- CodeRegionDirective.cs
- Graphics.cs
- TextEditorParagraphs.cs
- FontStretchConverter.cs
- QueryCacheEntry.cs
- StateManagedCollection.cs
- TemplatePropertyEntry.cs
- GenericsNotImplementedException.cs
- XmlDownloadManager.cs
- ListViewHitTestInfo.cs
- Stack.cs
- DragEvent.cs
- InvokeHandlers.cs
- Oci.cs
- JsonStringDataContract.cs
- Rule.cs
- IdentityReference.cs
- WindowsListViewItemCheckBox.cs
- PreviewControlDesigner.cs
- MenuItem.cs
- DictionaryItemsCollection.cs
- ToolstripProfessionalRenderer.cs
- FormViewUpdateEventArgs.cs
- WebPartMovingEventArgs.cs
- XsdValidatingReader.cs
- BitmapEffectrendercontext.cs
- TextCollapsingProperties.cs
- TraceContext.cs
- StreamWithDictionary.cs
- ModuleElement.cs
- ElementsClipboardData.cs
- MergeLocalizationDirectives.cs
- WebPartEventArgs.cs
- SqlRetyper.cs
- ExpressionEvaluator.cs
- Trigger.cs
- DataSourceSelectArguments.cs
- Imaging.cs
- DBAsyncResult.cs
- VideoDrawing.cs
- PropVariant.cs
- SqlVisitor.cs
- Stackframe.cs
- ObfuscateAssemblyAttribute.cs
- TdsParameterSetter.cs
- XomlCompilerResults.cs
- SingleKeyFrameCollection.cs
- Util.cs
- SiteMapHierarchicalDataSourceView.cs
- KeyToListMap.cs
- CompiledQuery.cs