Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / CommonUI / System / Drawing / SolidBrush.cs / 2 / SolidBrush.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Drawing { using System.Runtime.InteropServices; using System.Diagnostics; using System; using Microsoft.Win32; using System.ComponentModel; using System.Drawing.Internal; ////// /// public sealed class SolidBrush : Brush, ISystemColorTracker { // GDI+ doesn't understand system colors, so we need to cache the value here private Color color = Color.Empty; private bool immutable; /** * Create a new solid fill brush object */ ////// Defines a brush made up of a single color. Brushes are /// used to fill graphics shapes such as rectangles, ellipses, pies, polygons, and paths. /// ////// /// public SolidBrush(Color color) { this.color = color; IntPtr brush = IntPtr.Zero; int status = SafeNativeMethods.Gdip.GdipCreateSolidFill(this.color.ToArgb(), out brush); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); SetNativeBrush(brush); if (color.IsSystemColor) SystemColorTracker.Add(this); } internal SolidBrush(Color color, bool immutable) : this(color) { this.immutable = immutable; } ////// Initializes a new instance of the ///class of the specified /// color. /// /// Constructor to initialized this object from a GDI+ Brush native pointer. /// internal SolidBrush( IntPtr nativeBrush ) { Debug.Assert( nativeBrush != IntPtr.Zero, "Initializing native brush with null." ); SetNativeBrush( nativeBrush ); } ////// /// Creates an exact copy of this public override object Clone() { IntPtr cloneBrush = IntPtr.Zero; int status = SafeNativeMethods.Gdip.GdipCloneBrush(new HandleRef(this, this.NativeBrush), out cloneBrush); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); // We intentionally lose the "immutable" bit. return new SolidBrush(cloneBrush); } ///. /// protected override void Dispose(bool disposing) { if (!disposing) { immutable = false; } else if (immutable) { throw new ArgumentException(SR.GetString(SR.CantChangeImmutableObjects, "Brush")); } base.Dispose(disposing); } /// /// /// public Color Color { get { if (this.color == Color.Empty) { int colorARGB = 0; int status = SafeNativeMethods.Gdip.GdipGetSolidFillColor(new HandleRef(this, this.NativeBrush), out colorARGB); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); this.color = Color.FromArgb(colorARGB); } // GDI+ doesn't understand system colors, so we can't use GdipGetSolidFillColor in the general case return this.color; } set { if (immutable) { throw new ArgumentException(SR.GetString(SR.CantChangeImmutableObjects, "Brush")); } if( this.color != value ) { Color oldColor = this.color; InternalSetColor(value); // if (value.IsSystemColor && !oldColor.IsSystemColor) { SystemColorTracker.Add(this); } } } } // Sets the color even if the brush is considered immutable private void InternalSetColor(Color value) { int status = SafeNativeMethods.Gdip.GdipSetSolidFillColor(new HandleRef(this, this.NativeBrush), value.ToArgb()); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); this.color = value; } ////// The color of this ///. /// /// void ISystemColorTracker.OnSystemColorChanged() { if( this.NativeBrush != IntPtr.Zero ){ InternalSetColor(color); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Drawing { using System.Runtime.InteropServices; using System.Diagnostics; using System; using Microsoft.Win32; using System.ComponentModel; using System.Drawing.Internal; ////// /// public sealed class SolidBrush : Brush, ISystemColorTracker { // GDI+ doesn't understand system colors, so we need to cache the value here private Color color = Color.Empty; private bool immutable; /** * Create a new solid fill brush object */ ////// Defines a brush made up of a single color. Brushes are /// used to fill graphics shapes such as rectangles, ellipses, pies, polygons, and paths. /// ////// /// public SolidBrush(Color color) { this.color = color; IntPtr brush = IntPtr.Zero; int status = SafeNativeMethods.Gdip.GdipCreateSolidFill(this.color.ToArgb(), out brush); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); SetNativeBrush(brush); if (color.IsSystemColor) SystemColorTracker.Add(this); } internal SolidBrush(Color color, bool immutable) : this(color) { this.immutable = immutable; } ////// Initializes a new instance of the ///class of the specified /// color. /// /// Constructor to initialized this object from a GDI+ Brush native pointer. /// internal SolidBrush( IntPtr nativeBrush ) { Debug.Assert( nativeBrush != IntPtr.Zero, "Initializing native brush with null." ); SetNativeBrush( nativeBrush ); } ////// /// Creates an exact copy of this public override object Clone() { IntPtr cloneBrush = IntPtr.Zero; int status = SafeNativeMethods.Gdip.GdipCloneBrush(new HandleRef(this, this.NativeBrush), out cloneBrush); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); // We intentionally lose the "immutable" bit. return new SolidBrush(cloneBrush); } ///. /// protected override void Dispose(bool disposing) { if (!disposing) { immutable = false; } else if (immutable) { throw new ArgumentException(SR.GetString(SR.CantChangeImmutableObjects, "Brush")); } base.Dispose(disposing); } /// /// /// public Color Color { get { if (this.color == Color.Empty) { int colorARGB = 0; int status = SafeNativeMethods.Gdip.GdipGetSolidFillColor(new HandleRef(this, this.NativeBrush), out colorARGB); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); this.color = Color.FromArgb(colorARGB); } // GDI+ doesn't understand system colors, so we can't use GdipGetSolidFillColor in the general case return this.color; } set { if (immutable) { throw new ArgumentException(SR.GetString(SR.CantChangeImmutableObjects, "Brush")); } if( this.color != value ) { Color oldColor = this.color; InternalSetColor(value); // if (value.IsSystemColor && !oldColor.IsSystemColor) { SystemColorTracker.Add(this); } } } } // Sets the color even if the brush is considered immutable private void InternalSetColor(Color value) { int status = SafeNativeMethods.Gdip.GdipSetSolidFillColor(new HandleRef(this, this.NativeBrush), value.ToArgb()); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); this.color = value; } ////// The color of this ///. /// /// void ISystemColorTracker.OnSystemColorChanged() { if( this.NativeBrush != IntPtr.Zero ){ InternalSetColor(color); } } } } // 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
- XmlSchemaAnnotation.cs
- XmlDocumentViewSchema.cs
- X500Name.cs
- RadioButtonFlatAdapter.cs
- XComponentModel.cs
- SqlDelegatedTransaction.cs
- TextUtf8RawTextWriter.cs
- XmlNamespaceDeclarationsAttribute.cs
- FlowLayoutSettings.cs
- NTAccount.cs
- ConfigurationManager.cs
- PassportPrincipal.cs
- HighlightVisual.cs
- ConfigurationManagerInternalFactory.cs
- XmlDocumentViewSchema.cs
- Function.cs
- Pens.cs
- MultipartContentParser.cs
- CultureTableRecord.cs
- SourceChangedEventArgs.cs
- DesignerSerializationVisibilityAttribute.cs
- GridViewCommandEventArgs.cs
- IndexedString.cs
- LeafCellTreeNode.cs
- UserPreferenceChangingEventArgs.cs
- APCustomTypeDescriptor.cs
- ToolStripMenuItemDesigner.cs
- EditorZoneBase.cs
- SRDisplayNameAttribute.cs
- WebDescriptionAttribute.cs
- HttpHandlersInstallComponent.cs
- SessionEndedEventArgs.cs
- WebPartDisplayMode.cs
- DialogWindow.cs
- WindowsFormsDesignerOptionService.cs
- ValueQuery.cs
- DependencyPropertyKind.cs
- EntityStoreSchemaGenerator.cs
- MailHeaderInfo.cs
- AsyncStreamReader.cs
- sqlinternaltransaction.cs
- NotificationContext.cs
- VirtualPathData.cs
- CodeDomSerializerBase.cs
- SetterTriggerConditionValueConverter.cs
- MexHttpBindingElement.cs
- EntityCodeGenerator.cs
- FormsAuthenticationUser.cs
- BaseDataBoundControl.cs
- PersonalizationProviderHelper.cs
- SByteStorage.cs
- FileSystemInfo.cs
- EntitySqlQueryCacheKey.cs
- XmlResolver.cs
- ListMarkerSourceInfo.cs
- RegexCompilationInfo.cs
- RegexCapture.cs
- DiffuseMaterial.cs
- ValidationResult.cs
- RSAPKCS1KeyExchangeFormatter.cs
- TextLine.cs
- HeaderCollection.cs
- SynchronousReceiveElement.cs
- IntegrationExceptionEventArgs.cs
- TcpPortSharing.cs
- SpellCheck.cs
- GridSplitterAutomationPeer.cs
- FragmentQueryKB.cs
- InfoCardPolicy.cs
- WindowsListViewScroll.cs
- WebColorConverter.cs
- HScrollProperties.cs
- Privilege.cs
- EventProviderTraceListener.cs
- CodePageEncoding.cs
- CollectionChangeEventArgs.cs
- AssociationSetMetadata.cs
- ByteStreamBufferedMessageData.cs
- UnsafeNativeMethods.cs
- BrushMappingModeValidation.cs
- MediaScriptCommandRoutedEventArgs.cs
- StorageEndPropertyMapping.cs
- PolicyValidationException.cs
- UriScheme.cs
- TaskFileService.cs
- MemberPath.cs
- ReaderWriterLockSlim.cs
- Propagator.cs
- ConfigXmlDocument.cs
- Label.cs
- ListControl.cs
- localization.cs
- DbLambda.cs
- CornerRadius.cs
- ExtensionFile.cs
- RealizationContext.cs
- WebBrowserContainer.cs
- LookupBindingPropertiesAttribute.cs
- ProfileParameter.cs
- DBConnectionString.cs