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
- KeySplineConverter.cs
- WebServiceMethodData.cs
- LambdaCompiler.Generated.cs
- ToolStripRendererSwitcher.cs
- PositiveTimeSpanValidator.cs
- WebHttpBindingCollectionElement.cs
- HTMLTextWriter.cs
- IConvertible.cs
- DbConnectionPoolCounters.cs
- PropertyTabChangedEvent.cs
- ServicesUtilities.cs
- ConfigXmlElement.cs
- SeparatorAutomationPeer.cs
- ExpressionBuilder.cs
- PropertyMap.cs
- SqlDeflator.cs
- indexingfiltermarshaler.cs
- SerializableReadOnlyDictionary.cs
- FunctionParameter.cs
- SimpleBitVector32.cs
- ToolStripSeparatorRenderEventArgs.cs
- SmtpReplyReaderFactory.cs
- ProfileGroupSettingsCollection.cs
- CodeDelegateInvokeExpression.cs
- PeerName.cs
- LambdaCompiler.cs
- SchemaRegistration.cs
- EntityDataSourceSelectedEventArgs.cs
- AttachedPropertyBrowsableForTypeAttribute.cs
- _ReceiveMessageOverlappedAsyncResult.cs
- BaseCAMarshaler.cs
- RangeBase.cs
- RawStylusSystemGestureInputReport.cs
- ConstrainedDataObject.cs
- AffineTransform3D.cs
- WorkflowQueue.cs
- SelectionProviderWrapper.cs
- GeneralTransform3DTo2DTo3D.cs
- SortableBindingList.cs
- ViewStateModeByIdAttribute.cs
- FlowDocumentPaginator.cs
- WebPartConnectionsCancelVerb.cs
- TdsParserSafeHandles.cs
- SafeHandles.cs
- TextTreeRootNode.cs
- CaseStatement.cs
- ListViewDesigner.cs
- MethodMessage.cs
- RangeValuePattern.cs
- TextBlockAutomationPeer.cs
- OleDbErrorCollection.cs
- HitTestParameters3D.cs
- PointConverter.cs
- DataControlFieldHeaderCell.cs
- SimplePropertyEntry.cs
- GenericPrincipal.cs
- XmlWellformedWriterHelpers.cs
- MasterPageBuildProvider.cs
- TreeNodeBinding.cs
- ProxyWebPart.cs
- ParameterBuilder.cs
- Compiler.cs
- AlternateView.cs
- GeometryDrawing.cs
- SafeNativeMethods.cs
- ProfileGroupSettingsCollection.cs
- ISO2022Encoding.cs
- FontCollection.cs
- SystemColors.cs
- UserControlCodeDomTreeGenerator.cs
- Fault.cs
- ErrorTableItemStyle.cs
- DataServiceEntityAttribute.cs
- AsmxEndpointPickerExtension.cs
- CounterCreationData.cs
- XmlNamespaceDeclarationsAttribute.cs
- MetaDataInfo.cs
- PartitionResolver.cs
- ResourceWriter.cs
- ConfigurationElement.cs
- BitmapEffectDrawingContextState.cs
- ManifestSignedXml.cs
- OLEDB_Enum.cs
- ModelItemDictionaryImpl.cs
- DataListItem.cs
- GroupLabel.cs
- SchemaDeclBase.cs
- ExpandCollapseIsCheckedConverter.cs
- GestureRecognitionResult.cs
- JapaneseLunisolarCalendar.cs
- AssemblyResourceLoader.cs
- MediaEntryAttribute.cs
- StoreItemCollection.cs
- HtmlTextBoxAdapter.cs
- ListBoxChrome.cs
- DataGrid.cs
- HttpRawResponse.cs
- HttpWebResponse.cs
- BamlTreeNode.cs
- DispatcherExceptionFilterEventArgs.cs