Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / WinForms / Managed / System / WinForms / PaintEvent.cs / 1 / PaintEvent.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Windows.Forms { using Microsoft.Win32; using System; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Windows.Forms.Internal; using System.Drawing.Drawing2D; using System.Runtime.InteropServices; ////// /// // NOTE: Please keep this class consistent with PrintPageEventArgs. public class PaintEventArgs : EventArgs, IDisposable { ////// Provides data for the ////// event. /// /// Graphics object with which painting should be done. /// private Graphics graphics = null; // See ResetGraphics() private GraphicsState savedGraphicsState = null; ////// DC (Display context) for obtaining the graphics object. Used to delay getting the graphics /// object until absolutely necessary (for perf reasons) /// private readonly IntPtr dc = IntPtr.Zero; IntPtr oldPal = IntPtr.Zero; ////// Rectangle into which all painting should be done. /// private readonly Rectangle clipRect; //private Control paletteSource; ////// /// public PaintEventArgs(Graphics graphics, Rectangle clipRect) { if( graphics == null ){ throw new ArgumentNullException("graphics"); } this.graphics = graphics; this.clipRect = clipRect; } // Internal version of constructor for performance // We try to avoid getting the graphics object until needed internal PaintEventArgs(IntPtr dc, Rectangle clipRect) { Debug.Assert(dc != IntPtr.Zero, "dc is not initialized."); this.dc = dc; this.clipRect = clipRect; } ////// Initializes a new instance of the ///class with the specified graphics and /// clipping rectangle. /// ~PaintEventArgs() { Dispose(false); } /// /// /// public Rectangle ClipRectangle { get { return clipRect; } } ////// Gets the /// rectangle in which to paint. /// ////// Gets the HDC this paint event is connected to. If there is no associated /// HDC, or the GDI+ Graphics object has been created (meaning GDI+ now owns the /// HDC), 0 is returned. /// /// internal IntPtr HDC { get { if (graphics == null) return dc; else return IntPtr.Zero; } } ////// /// public System.Drawing.Graphics Graphics { get { if (graphics == null && dc != IntPtr.Zero) { oldPal = Control.SetUpPalette(dc, false /*force*/, false /*realize*/); graphics = Graphics.FromHdcInternal(dc); graphics.PageUnit = GraphicsUnit.Pixel; savedGraphicsState = graphics.Save(); // See ResetGraphics() below } return graphics; } } // We want a way to dispose the GDI+ Graphics, but we don't want to create one // simply to dispose it // cpr: should be internal ////// Gets the ////// object used to /// paint. /// /// /// public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } ////// Disposes /// of the resources (other than memory) used by the ///. /// protected virtual void Dispose(bool disposing) { if (disposing) { //only dispose the graphics object if we created it via the dc. if (graphics != null && dc != IntPtr.Zero) { graphics.Dispose(); } } if (oldPal != IntPtr.Zero && dc != IntPtr.Zero) { SafeNativeMethods.SelectPalette(new HandleRef(this, dc), new HandleRef(this, oldPal), 0); oldPal = IntPtr.Zero; } } // If ControlStyles.AllPaintingInWmPaint, we call this method // after OnPaintBackground so it appears to OnPaint that it's getting a fresh // Graphics. We want to make sure AllPaintingInWmPaint is purely an optimization, // and doesn't change behavior, so we need to make sure any clipping regions established // in OnPaintBackground don't apply to OnPaint. See ASURT 44682. internal void ResetGraphics() { if (graphics != null) { Debug.Assert(dc == IntPtr.Zero || savedGraphicsState != null, "Called ResetGraphics more than once?"); if (savedGraphicsState != null) { graphics.Restore(savedGraphicsState); savedGraphicsState = null; } } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Windows.Forms { using Microsoft.Win32; using System; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Windows.Forms.Internal; using System.Drawing.Drawing2D; using System.Runtime.InteropServices; ////// /// // NOTE: Please keep this class consistent with PrintPageEventArgs. public class PaintEventArgs : EventArgs, IDisposable { ////// Provides data for the ////// event. /// /// Graphics object with which painting should be done. /// private Graphics graphics = null; // See ResetGraphics() private GraphicsState savedGraphicsState = null; ////// DC (Display context) for obtaining the graphics object. Used to delay getting the graphics /// object until absolutely necessary (for perf reasons) /// private readonly IntPtr dc = IntPtr.Zero; IntPtr oldPal = IntPtr.Zero; ////// Rectangle into which all painting should be done. /// private readonly Rectangle clipRect; //private Control paletteSource; ////// /// public PaintEventArgs(Graphics graphics, Rectangle clipRect) { if( graphics == null ){ throw new ArgumentNullException("graphics"); } this.graphics = graphics; this.clipRect = clipRect; } // Internal version of constructor for performance // We try to avoid getting the graphics object until needed internal PaintEventArgs(IntPtr dc, Rectangle clipRect) { Debug.Assert(dc != IntPtr.Zero, "dc is not initialized."); this.dc = dc; this.clipRect = clipRect; } ////// Initializes a new instance of the ///class with the specified graphics and /// clipping rectangle. /// ~PaintEventArgs() { Dispose(false); } /// /// /// public Rectangle ClipRectangle { get { return clipRect; } } ////// Gets the /// rectangle in which to paint. /// ////// Gets the HDC this paint event is connected to. If there is no associated /// HDC, or the GDI+ Graphics object has been created (meaning GDI+ now owns the /// HDC), 0 is returned. /// /// internal IntPtr HDC { get { if (graphics == null) return dc; else return IntPtr.Zero; } } ////// /// public System.Drawing.Graphics Graphics { get { if (graphics == null && dc != IntPtr.Zero) { oldPal = Control.SetUpPalette(dc, false /*force*/, false /*realize*/); graphics = Graphics.FromHdcInternal(dc); graphics.PageUnit = GraphicsUnit.Pixel; savedGraphicsState = graphics.Save(); // See ResetGraphics() below } return graphics; } } // We want a way to dispose the GDI+ Graphics, but we don't want to create one // simply to dispose it // cpr: should be internal ////// Gets the ////// object used to /// paint. /// /// /// public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } ////// Disposes /// of the resources (other than memory) used by the ///. /// protected virtual void Dispose(bool disposing) { if (disposing) { //only dispose the graphics object if we created it via the dc. if (graphics != null && dc != IntPtr.Zero) { graphics.Dispose(); } } if (oldPal != IntPtr.Zero && dc != IntPtr.Zero) { SafeNativeMethods.SelectPalette(new HandleRef(this, dc), new HandleRef(this, oldPal), 0); oldPal = IntPtr.Zero; } } // If ControlStyles.AllPaintingInWmPaint, we call this method // after OnPaintBackground so it appears to OnPaint that it's getting a fresh // Graphics. We want to make sure AllPaintingInWmPaint is purely an optimization, // and doesn't change behavior, so we need to make sure any clipping regions established // in OnPaintBackground don't apply to OnPaint. See ASURT 44682. internal void ResetGraphics() { if (graphics != null) { Debug.Assert(dc == IntPtr.Zero || savedGraphicsState != null, "Called ResetGraphics more than once?"); if (savedGraphicsState != null) { graphics.Restore(savedGraphicsState); savedGraphicsState = null; } } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- PageContent.cs
- ScriptResourceInfo.cs
- M3DUtil.cs
- SqlRowUpdatedEvent.cs
- _ContextAwareResult.cs
- CommandValueSerializer.cs
- log.cs
- OracleNumber.cs
- VersionedStream.cs
- OutOfProcStateClientManager.cs
- CopyAttributesAction.cs
- UIElementIsland.cs
- FixedSOMPageElement.cs
- CheckBoxPopupAdapter.cs
- StylusPointPropertyInfoDefaults.cs
- RegexBoyerMoore.cs
- InvalidOperationException.cs
- AttributeSetAction.cs
- CacheMode.cs
- PropertyKey.cs
- ProviderMetadataCachedInformation.cs
- PackageDigitalSignatureManager.cs
- Overlapped.cs
- BuildProviderCollection.cs
- IdentityManager.cs
- DataTableTypeConverter.cs
- IndexedGlyphRun.cs
- LoadWorkflowByKeyAsyncResult.cs
- SQLGuidStorage.cs
- SchemaNotation.cs
- CaseCqlBlock.cs
- Label.cs
- DirectoryNotFoundException.cs
- DataReaderContainer.cs
- RequiredFieldValidator.cs
- TemplateBindingExtensionConverter.cs
- COM2IVsPerPropertyBrowsingHandler.cs
- CommunicationObjectAbortedException.cs
- XmlEncoding.cs
- XmlEnumAttribute.cs
- TabletCollection.cs
- ProfileBuildProvider.cs
- DBPropSet.cs
- TemplateControl.cs
- WeakKeyDictionary.cs
- BaseTreeIterator.cs
- TemplateContainer.cs
- VScrollProperties.cs
- GridViewSortEventArgs.cs
- CallbackValidator.cs
- MarkupObject.cs
- _StreamFramer.cs
- PathFigure.cs
- AuthenticationService.cs
- FutureFactory.cs
- PopupRootAutomationPeer.cs
- AttributeCollection.cs
- Attachment.cs
- WebEventTraceProvider.cs
- COMException.cs
- PreloadedPackages.cs
- MappingItemCollection.cs
- RequestQueue.cs
- PrePostDescendentsWalker.cs
- ThreadInterruptedException.cs
- WebBrowserUriTypeConverter.cs
- CodeAttributeDeclaration.cs
- XamlRtfConverter.cs
- ToolStripOverflow.cs
- SessionState.cs
- VerticalAlignConverter.cs
- CanonicalFormWriter.cs
- KerberosRequestorSecurityToken.cs
- X509RawDataKeyIdentifierClause.cs
- Wizard.cs
- Int32.cs
- CriticalHandle.cs
- FastEncoderWindow.cs
- TransformerTypeCollection.cs
- DataGridColumnHeader.cs
- TreeViewImageIndexConverter.cs
- Token.cs
- ParallelSeparator.xaml.cs
- XmlSchemaComplexContentRestriction.cs
- SerializationFieldInfo.cs
- UrlPath.cs
- ServiceModelActivationSectionGroup.cs
- NestedContainer.cs
- PolicyConversionContext.cs
- LineSegment.cs
- AdjustableArrowCap.cs
- TiffBitmapEncoder.cs
- Normalization.cs
- UIElement3D.cs
- DocumentPageHost.cs
- ObjectDataSourceEventArgs.cs
- MemberDomainMap.cs
- _ShellExpression.cs
- MetadataPropertyCollection.cs
- MeasureItemEvent.cs