AmbientValueAttribute Klasa

Definicja

Określa wartość, która ma być przekazywana do właściwości, aby spowodować, że właściwość pobierze jej wartość z innego źródła. Jest to znane jako atmosfera. Klasa ta nie może być dziedziczona.

public ref class AmbientValueAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.All)]
public sealed class AmbientValueAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.All)>]
type AmbientValueAttribute = class
    inherit Attribute
Public NotInheritable Class AmbientValueAttribute
Inherits Attribute
Dziedziczenie
AmbientValueAttribute
Atrybuty

Przykłady

W poniższym przykładzie kodu pokazano użycie metody AmbientValueAttribute wymuszania zachowania otoczenia dla właściwości o nazwie AlertForeColor. Aby uzyskać pełną listę kodu, zobacz How to: Apply Attributes in Windows Forms Controls (Instrukcje: stosowanie atrybutów w kontrolkach Windows Forms).

[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);
}
<AmbientValue(GetType(Color), "Empty"), _
Category("Appearance"), _
DefaultValue(GetType(Color), "White"), _
Description("The color used for painting alert text.")> _
Public Property AlertForeColor() As Color
    Get
        If Me.alertForeColorValue = Color.Empty AndAlso (Me.Parent IsNot Nothing) Then
            Return Parent.ForeColor
        End If

        Return Me.alertForeColorValue
    End Get

    Set(ByVal value As Color)
        Me.alertForeColorValue = value
    End Set
End Property

' This method is used by designers to enable resetting the
' property to its default value.
Public Sub ResetAlertForeColor()
    Me.AlertForeColor = AttributesDemoControl.defaultAlertForeColorValue
End Sub

' 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 Function ShouldSerializeAlertForeColor() As Boolean
    Return Me.alertForeColorValue <> AttributesDemoControl.ambientColorValue
End Function

Uwagi

Jeśli właściwość kontrolki ma zachowanie otoczenia, ten atrybut musi być obecny. Właściwości otoczenia wysyłają zapytanie o ich wartość nadrzędną Control.FontControl.BackColor , na przykład właściwość lub właściwość.

Zazwyczaj projektant wizualizacji używa atrybutu AmbientValueAttribute , aby zdecydować, która wartość ma być utrwalana dla właściwości. Jest to zwykle wartość, która powoduje, że właściwość pobiera swoją wartość z innego źródła. Przykładem wartości otoczenia jest Color.Empty wartość otoczenia dla BackColor właściwości. Jeśli masz kontrolkę w formularzu, a BackColor właściwość kontrolki jest ustawiona na inny kolor niż BackColor właściwość formularza, możesz zresetować BackColor właściwość kontrolki do formularza, ustawiając BackColor kontrolkę na Color.Empty.

Konstruktory

AmbientValueAttribute(Boolean)

Inicjuje AmbientValueAttribute nowe wystąpienie klasy, biorąc pod uwagę wartość logiczną dla jej wartości.

AmbientValueAttribute(Byte)

Inicjuje AmbientValueAttribute nowe wystąpienie klasy, biorąc pod uwagę 8-bitową liczbę całkowitą bez znaku dla jej wartości.

AmbientValueAttribute(Char)

Inicjuje AmbientValueAttribute nowe wystąpienie klasy, biorąc pod uwagę znak Unicode dla jego wartości.

AmbientValueAttribute(Double)

Inicjuje AmbientValueAttribute nowe wystąpienie klasy, biorąc pod uwagę liczbę zmiennoprzecinkową o podwójnej precyzji dla jej wartości.

AmbientValueAttribute(Int16)

Inicjuje AmbientValueAttribute nowe wystąpienie klasy, biorąc pod uwagę 16-bitową liczbę całkowitą ze znakiem dla jej wartości.

AmbientValueAttribute(Int32)

Inicjuje AmbientValueAttribute nowe wystąpienie klasy, przy użyciu 32-bitowej liczby całkowitej ze znakiem dla jego wartości.

AmbientValueAttribute(Int64)

Inicjuje AmbientValueAttribute nowe wystąpienie klasy, biorąc pod uwagę 64-bitową liczbę całkowitą ze znakiem dla jej wartości.

AmbientValueAttribute(Object)

Inicjuje AmbientValueAttribute nowe wystąpienie klasy, biorąc pod uwagę obiekt dla jego wartości.

AmbientValueAttribute(Single)

Inicjuje AmbientValueAttribute nowe wystąpienie klasy, biorąc pod uwagę liczbę zmiennoprzecinkową o pojedynczej precyzji dla jej wartości.

AmbientValueAttribute(String)

Inicjuje AmbientValueAttribute nowe wystąpienie klasy, biorąc pod uwagę ciąg dla jego wartości.

AmbientValueAttribute(Type, String)

Inicjuje AmbientValueAttribute nowe wystąpienie klasy, biorąc pod uwagę wartość i jego typ.

Właściwości

TypeId

Po zaimplementowaniu w klasie pochodnej pobiera unikatowy identyfikator dla tego elementu Attribute.

(Odziedziczone po Attribute)
Value

Pobiera obiekt, który jest wartością tego AmbientValueAttributeobiektu .

Metody

Equals(Object)

Określa, czy określona wartość AmbientValueAttribute jest równa bieżącemu AmbientValueAttribute.

GetHashCode()

Zwraca wartość skrótu dla tego wystąpienia.

GetType()

Type Pobiera bieżące wystąpienie.

(Odziedziczone po Object)
IsDefaultAttribute()

W przypadku zastąpienia w klasie pochodnej wskazuje, czy wartość tego wystąpienia jest wartością domyślną klasy pochodnej.

(Odziedziczone po Attribute)
Match(Object)

W przypadku zastąpienia w klasie pochodnej zwraca wartość wskazującą, czy to wystąpienie jest równe określonemu obiektowi.

(Odziedziczone po Attribute)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Jawne implementacje interfejsu

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Zestaw nazw jest mapowany na odpowiedni zestaw identyfikatorów wysyłania.

(Odziedziczone po Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Pobiera informacje o typie obiektu, którego można użyć do pobrania informacji o typie interfejsu.

(Odziedziczone po Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Pobiera informację o liczbie typów interfejsów, jakie zawiera obiekt (0 lub 1).

(Odziedziczone po Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Umożliwia dostęp do właściwości i metod udostępnianych przez obiekt.

(Odziedziczone po Attribute)

Dotyczy