AmbientValueAttribute Class
TOC
Collapse the table of content
Expand the table of content

AmbientValueAttribute Class

 

Specifies the value to pass to a property to cause the property to get its value from another source. This is known as ambience. This class cannot be inherited.

Namespace:   System.ComponentModel
Assembly:  System (in System.dll)

System.Object
  System.Attribute
    System.ComponentModel.AmbientValueAttribute

[AttributeUsageAttribute(AttributeTargets.All)]
public sealed class AmbientValueAttribute : Attribute

NameDescription
System_CAPS_pubmethodAmbientValueAttribute(Boolean)

Initializes a new instance of the AmbientValueAttribute class, given a Boolean value for its value.

System_CAPS_pubmethodAmbientValueAttribute(Byte)

Initializes a new instance of the AmbientValueAttribute class, given an 8-bit unsigned integer for its value.

System_CAPS_pubmethodAmbientValueAttribute(Char)

Initializes a new instance of the AmbientValueAttribute class, given a Unicode character for its value.

System_CAPS_pubmethodAmbientValueAttribute(Double)

Initializes a new instance of the AmbientValueAttribute class, given a double-precision floating-point number for its value.

System_CAPS_pubmethodAmbientValueAttribute(Int16)

Initializes a new instance of the AmbientValueAttribute class, given a 16-bit signed integer for its value.

System_CAPS_pubmethodAmbientValueAttribute(Int32)

Initializes a new instance of the AmbientValueAttribute class, given a 32-bit signed integer for its value.

System_CAPS_pubmethodAmbientValueAttribute(Int64)

Initializes a new instance of the AmbientValueAttribute class, given a 64-bit signed integer for its value.

System_CAPS_pubmethodAmbientValueAttribute(Object)

Initializes a new instance of the AmbientValueAttribute class, given an object for its value.

System_CAPS_pubmethodAmbientValueAttribute(Single)

Initializes a new instance of the AmbientValueAttribute class, given a single-precision floating point number for its value.

System_CAPS_pubmethodAmbientValueAttribute(String)

Initializes a new instance of the AmbientValueAttribute class, given a string for its value.

System_CAPS_pubmethodAmbientValueAttribute(Type, String)

Initializes a new instance of the AmbientValueAttribute class, given the value and its type.

NameDescription
System_CAPS_pubpropertyTypeId

When implemented in a derived class, gets a unique identifier for this Attribute.(Inherited from Attribute.)

System_CAPS_pubpropertyValue

Gets the object that is the value of this AmbientValueAttribute.

NameDescription
System_CAPS_pubmethodEquals(Object)

Determines whether the specified AmbientValueAttribute is equal to the current AmbientValueAttribute.(Overrides Attribute.Equals(Object).)

System_CAPS_pubmethodGetHashCode()

Returns the hash code for this instance.(Overrides Attribute.GetHashCode().)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodIsDefaultAttribute()

When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.(Inherited from Attribute.)

System_CAPS_pubmethodMatch(Object)

When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.(Inherited from Attribute.)

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_privmethod_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Maps a set of names to a corresponding set of dispatch identifiers.(Inherited from Attribute.)

System_CAPS_pubinterfaceSystem_CAPS_privmethod_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Retrieves the type information for an object, which can be used to get the type information for an interface.(Inherited from Attribute.)

System_CAPS_pubinterfaceSystem_CAPS_privmethod_Attribute.GetTypeInfoCount(UInt32)

Retrieves the number of type information interfaces that an object provides (either 0 or 1).(Inherited from Attribute.)

System_CAPS_pubinterfaceSystem_CAPS_privmethod_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Provides access to properties and methods exposed by an object.(Inherited from Attribute.)

If a property on a control has ambient behavior, this attribute must be present. Ambient properties query their parent for their value, for example, a Control.Font property or a Control.BackColor property.

Typically, a visual designer uses the AmbientValueAttribute attribute to decide which value to persist for a property. This is usually a value that causes the property to get its value from another source. An example of an ambient value is Color.Empty as the ambient value for the BackColor property. If you have a control on a form and the BackColor property of the control is set to a different color than the BackColor property of the form, you can reset the BackColor property of the control to that of the form by setting the BackColor of the control to Color.Empty.

The following code example demonstrates using AmbientValueAttribute to enforce ambient behavior for a property called AlertForeColor. For a full code listing, see How to: Apply Attributes in Windows Forms Controls.

[AmbientValue(typeof(Color), "Empty")]
[Category("Appearance")]
[DefaultValue(typeof(Color), "White")]
[Description("The color used for painting alert text.")]
public Color AlertForeColor
{
    get
    {
        if (this.alertForeColorValue == Color.Empty &&
            this.Parent != null)
        {
            return Parent.ForeColor;
        }

        return this.alertForeColorValue;
    }

    set
    {
        this.alertForeColorValue = value;
    }
}

// This method is used by designers to enable resetting the
// property to its default value.
public void ResetAlertForeColor()
{
    this.AlertForeColor = AttributesDemoControl.defaultAlertForeColorValue;
}

// This method indicates to designers whether the property
// value is different from the ambient value, in which case
// the designer should persist the value.
private bool ShouldSerializeAlertForeColor()
{
    return (this.alertForeColorValue != AttributesDemoControl.ambientColorValue);
}

.NET Framework
Available since 1.1

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show:
© 2016 Microsoft