Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / CommonUI / System / Drawing / SolidBrush.cs / 1 / SolidBrush.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
/*************************************************************************\
*
* Copyright (c) 1998-1999, Microsoft Corp. All Rights Reserved.
*
* Module Name:
*
* SolidBrush.cs
*
* Abstract:
*
* COM+ wrapper for GDI+ SolidBrush objects
*
* Revision History:
*
* 12/15/1998 [....]
* Created it.
*
\**************************************************************************/
namespace System.Drawing {
using System.Runtime.InteropServices;
using System.Diagnostics;
using System;
using Microsoft.Win32;
using System.ComponentModel;
using System.Drawing.Internal;
///
///
///
/// 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.
///
///
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;
}
///
/// 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);
}
///
///
///
/// 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.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- FontSizeConverter.cs
- PixelFormat.cs
- ServiceThrottle.cs
- ProcessHostServerConfig.cs
- CustomAttributeSerializer.cs
- WebServiceResponse.cs
- RenderDataDrawingContext.cs
- ExpressionBindingCollection.cs
- XComponentModel.cs
- Configuration.cs
- AsymmetricSignatureDeformatter.cs
- MemoryMappedView.cs
- HttpGetProtocolImporter.cs
- WaitForChangedResult.cs
- AutoCompleteStringCollection.cs
- SnapshotChangeTrackingStrategy.cs
- CompiledELinqQueryState.cs
- RenderDataDrawingContext.cs
- EmbeddedMailObjectsCollection.cs
- FlowDecision.cs
- Misc.cs
- PriorityRange.cs
- StringResourceManager.cs
- UInt16.cs
- DesignTimeHTMLTextWriter.cs
- TreeNodeBindingCollection.cs
- TextClipboardData.cs
- Pair.cs
- RayMeshGeometry3DHitTestResult.cs
- StringBuilder.cs
- FolderBrowserDialog.cs
- OdbcError.cs
- OracleDataReader.cs
- InstanceStore.cs
- MultiAsyncResult.cs
- TemplateInstanceAttribute.cs
- GetMemberBinder.cs
- CalculatedColumn.cs
- ButtonFlatAdapter.cs
- ComponentSerializationService.cs
- ComponentCommands.cs
- SafeFileHandle.cs
- IBuiltInEvidence.cs
- ScaleTransform.cs
- DataGridViewDataErrorEventArgs.cs
- Int32.cs
- QuadTree.cs
- ServiceOperationParameter.cs
- UnsafeNativeMethods.cs
- Nodes.cs
- MessageQueuePermissionEntry.cs
- XmlSchemaDocumentation.cs
- Trigger.cs
- IriParsingElement.cs
- XmlLoader.cs
- Transform3D.cs
- Exception.cs
- OrderedHashRepartitionStream.cs
- NativeMethods.cs
- XamlFigureLengthSerializer.cs
- PassportPrincipal.cs
- ColumnMap.cs
- ThousandthOfEmRealPoints.cs
- BuiltInExpr.cs
- BaseParagraph.cs
- HwndSourceKeyboardInputSite.cs
- Match.cs
- SymbolDocumentInfo.cs
- Literal.cs
- WebAdminConfigurationHelper.cs
- NativeMethods.cs
- PersonalizationAdministration.cs
- XmlDocument.cs
- ListBoxItemWrapperAutomationPeer.cs
- SystemColors.cs
- DynamicMethod.cs
- ListDictionary.cs
- SpoolingTask.cs
- CookieParameter.cs
- SplitterEvent.cs
- AnchorEditor.cs
- MergePropertyDescriptor.cs
- BooleanFunctions.cs
- AnnotationService.cs
- ManagementQuery.cs
- EntityDataSourceValidationException.cs
- ScopeCompiler.cs
- tooltip.cs
- BaseTypeViewSchema.cs
- CommandValueSerializer.cs
- AbstractDataSvcMapFileLoader.cs
- XmlHierarchyData.cs
- ObjectStateManagerMetadata.cs
- MetafileHeaderWmf.cs
- RectangleHotSpot.cs
- DataGridViewHeaderCell.cs
- QilBinary.cs
- SmtpNegotiateAuthenticationModule.cs
- HiddenFieldPageStatePersister.cs
- LicenseManager.cs