Freigeben über


AmbientValueAttribute-Konstruktor (Type, String)

Initialisiert eine neue Instanz der AmbientValueAttribute-Klasse, sofern der Wert und dessen Typ angegeben sind.

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

Syntax

'Declaration
Public Sub New ( _
    type As Type, _
    value As String _
)
'Usage
Dim type As Type
Dim value As String

Dim instance As New AmbientValueAttribute(type, value)
public AmbientValueAttribute (
    Type type,
    string value
)
public:
AmbientValueAttribute (
    Type^ type, 
    String^ value
)
public AmbientValueAttribute (
    Type type, 
    String value
)
public function AmbientValueAttribute (
    type : Type, 
    value : String
)

Parameter

  • type
    Der Type des value-Parameters.
  • value
    Der Wert für dieses Attribut.

Beispiel

Im folgenden Codebeispiel wird die Verwendung von AmbientValueAttribute veranschaulicht, um das umgebungsabhängige Verhalten für eine Eigenschaft mit der Bezeichnung AlertForeColor zu erzwingen. Eine vollständige Codeauflistung finden Sie unter Gewusst wie: Anwenden von Attributen auf Windows Forms-Steuerelemente.

<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 Not (Me.Parent Is 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
[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);
}

Plattformen

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

AmbientValueAttribute-Klasse
AmbientValueAttribute-Member
System.ComponentModel-Namespace