Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / CommonUI / System / Drawing / SolidBrush.cs / 1305376 / 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;
using System.Runtime.Versioning;
///
///
///
/// 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 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
*/
///
///
///
/// Initializes a new instance of the class of the specified
/// color.
///
///
[ResourceExposure(ResourceScope.Process)]
[ResourceConsumption(ResourceScope.Process)]
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);
SetNativeBrushInternal(brush);
if (color.IsSystemColor)
SystemColorTracker.Add(this);
}
[ResourceExposure(ResourceScope.Process)]
[ResourceConsumption(ResourceScope.Process)]
internal SolidBrush(Color color, bool immutable) : this(color) {
this.immutable = immutable;
}
///
/// 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." );
SetNativeBrushInternal( nativeBrush );
}
///
///
/// Creates an exact copy of this .
///
[ResourceExposure(ResourceScope.Process)]
[ResourceConsumption(ResourceScope.Process)]
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);
}
///
///
///
/// The color of this .
///
///
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;
}
///
///
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;
using System.Runtime.Versioning;
///
///
///
/// 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 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
*/
///
///
///
/// Initializes a new instance of the class of the specified
/// color.
///
///
[ResourceExposure(ResourceScope.Process)]
[ResourceConsumption(ResourceScope.Process)]
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);
SetNativeBrushInternal(brush);
if (color.IsSystemColor)
SystemColorTracker.Add(this);
}
[ResourceExposure(ResourceScope.Process)]
[ResourceConsumption(ResourceScope.Process)]
internal SolidBrush(Color color, bool immutable) : this(color) {
this.immutable = immutable;
}
///
/// 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." );
SetNativeBrushInternal( nativeBrush );
}
///
///
/// Creates an exact copy of this .
///
[ResourceExposure(ResourceScope.Process)]
[ResourceConsumption(ResourceScope.Process)]
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);
}
///
///
///
/// The color of this .
///
///
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;
}
///
///
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
- AnnotationStore.cs
- ExceptionAggregator.cs
- Array.cs
- CurrentTimeZone.cs
- XmlAtomicValue.cs
- Condition.cs
- DataGridViewButtonColumn.cs
- XmlSerializationGeneratedCode.cs
- FixedHighlight.cs
- DelimitedListTraceListener.cs
- BinaryFormatterWriter.cs
- HtmlGenericControl.cs
- DocumentApplicationJournalEntryEventArgs.cs
- ConstrainedDataObject.cs
- Track.cs
- TreeNode.cs
- ToolStripDropDownButton.cs
- FileDialogPermission.cs
- DomainUpDown.cs
- activationcontext.cs
- ConstNode.cs
- SystemEvents.cs
- DeclarativeCatalogPart.cs
- TimeBoundedCache.cs
- BaseParser.cs
- XmlWrappingWriter.cs
- TemplateControlParser.cs
- ConnectionManagementSection.cs
- Emitter.cs
- ConcurrentStack.cs
- SpotLight.cs
- ContentFilePart.cs
- UTF8Encoding.cs
- PropertyGrid.cs
- SqlDataSourceSummaryPanel.cs
- XPathConvert.cs
- QilUnary.cs
- CheckPair.cs
- XmlAttributeProperties.cs
- WebBrowserNavigatedEventHandler.cs
- Single.cs
- GrammarBuilderDictation.cs
- XmlName.cs
- BeginEvent.cs
- XmlBindingWorker.cs
- LineVisual.cs
- _ListenerResponseStream.cs
- ConfigXmlAttribute.cs
- BeginStoryboard.cs
- BaseParser.cs
- CounterSetInstance.cs
- TimeManager.cs
- AttachedAnnotationChangedEventArgs.cs
- GatewayIPAddressInformationCollection.cs
- ModuleBuilderData.cs
- DrawListViewSubItemEventArgs.cs
- TextRangeSerialization.cs
- MsmqIntegrationInputMessage.cs
- MimeFormatExtensions.cs
- DataGridViewRow.cs
- FaultCallbackWrapper.cs
- MessageBuffer.cs
- DoubleAnimationClockResource.cs
- InputScope.cs
- DeclaredTypeElement.cs
- PagesChangedEventArgs.cs
- ListBindingConverter.cs
- oledbconnectionstring.cs
- ResourceKey.cs
- ByteStreamGeometryContext.cs
- XmlIterators.cs
- SettingsPropertyNotFoundException.cs
- KeyedCollection.cs
- ComponentDispatcherThread.cs
- XmlSchemaSimpleTypeUnion.cs
- DesignRelationCollection.cs
- NamedPermissionSet.cs
- MultiBindingExpression.cs
- ToolTipAutomationPeer.cs
- Triplet.cs
- WebContext.cs
- QueryPageSettingsEventArgs.cs
- DataGridViewComboBoxCell.cs
- StatusBarItemAutomationPeer.cs
- StringSource.cs
- EntitySetBaseCollection.cs
- JsonReaderDelegator.cs
- ExeConfigurationFileMap.cs
- TabControlAutomationPeer.cs
- HostingEnvironmentException.cs
- SHA1CryptoServiceProvider.cs
- DelegatedStream.cs
- RecordsAffectedEventArgs.cs
- ComNativeDescriptor.cs
- NativeObjectSecurity.cs
- CompositeActivityTypeDescriptor.cs
- SqlDataSourceView.cs
- Compiler.cs
- TargetControlTypeCache.cs
- DataTableReader.cs