AmbientValueAttribute 建構函式

定義

初始化 AmbientValueAttribute 類別的新執行個體。

多載

AmbientValueAttribute(Boolean)

初始化 AmbientValueAttribute 類別的新執行個體,需指定其值為 Boolean 值。

AmbientValueAttribute(Byte)

初始化 AmbientValueAttribute 類別的新執行個體,需指定其值為 8 位元不帶正負號的整數 (Unsigned Integer)。

AmbientValueAttribute(Char)

初始化 AmbientValueAttribute 類別的新執行個體,需指定其值為 Unicode 字元。

AmbientValueAttribute(Double)

初始化 AmbientValueAttribute 類別的新執行個體,需指定其值為雙精度浮點數。

AmbientValueAttribute(Int16)

初始化 AmbientValueAttribute 類別的新執行個體,需指定其值為 16 位元帶正負號的整數。

AmbientValueAttribute(Int32)

初始化 AmbientValueAttribute 類別的新執行個體,需指定其值為 32 位元帶正負號的整數。

AmbientValueAttribute(Int64)

初始化 AmbientValueAttribute 類別的新執行個體,需指定其值為 64 位元帶正負號的整數。

AmbientValueAttribute(Object)

初始化 AmbientValueAttribute 類別的新執行個體,需指定其值為物件。

AmbientValueAttribute(Single)

初始化 AmbientValueAttribute 類別的新執行個體,需指定其值為單精確度浮點數。

AmbientValueAttribute(String)

初始化 AmbientValueAttribute 類別的新執行個體,需指定其值為字串。

AmbientValueAttribute(Type, String)

初始化 AmbientValueAttribute 類別的新執行個體,需指定值和型別。

AmbientValueAttribute(Boolean)

來源:
AmbientValueAttribute.cs
來源:
AmbientValueAttribute.cs
來源:
AmbientValueAttribute.cs

初始化 AmbientValueAttribute 類別的新執行個體,需指定其值為 Boolean 值。

public:
 AmbientValueAttribute(bool value);
public AmbientValueAttribute (bool value);
new System.ComponentModel.AmbientValueAttribute : bool -> System.ComponentModel.AmbientValueAttribute
Public Sub New (value As Boolean)

參數

value
Boolean

這個屬性的值。

適用於

AmbientValueAttribute(Byte)

來源:
AmbientValueAttribute.cs
來源:
AmbientValueAttribute.cs
來源:
AmbientValueAttribute.cs

初始化 AmbientValueAttribute 類別的新執行個體,需指定其值為 8 位元不帶正負號的整數 (Unsigned Integer)。

public:
 AmbientValueAttribute(System::Byte value);
public AmbientValueAttribute (byte value);
new System.ComponentModel.AmbientValueAttribute : byte -> System.ComponentModel.AmbientValueAttribute
Public Sub New (value As Byte)

參數

value
Byte

這個屬性的值。

適用於

AmbientValueAttribute(Char)

來源:
AmbientValueAttribute.cs
來源:
AmbientValueAttribute.cs
來源:
AmbientValueAttribute.cs

初始化 AmbientValueAttribute 類別的新執行個體,需指定其值為 Unicode 字元。

public:
 AmbientValueAttribute(char value);
public AmbientValueAttribute (char value);
new System.ComponentModel.AmbientValueAttribute : char -> System.ComponentModel.AmbientValueAttribute
Public Sub New (value As Char)

參數

value
Char

這個屬性的值。

適用於

AmbientValueAttribute(Double)

來源:
AmbientValueAttribute.cs
來源:
AmbientValueAttribute.cs
來源:
AmbientValueAttribute.cs

初始化 AmbientValueAttribute 類別的新執行個體,需指定其值為雙精度浮點數。

public:
 AmbientValueAttribute(double value);
public AmbientValueAttribute (double value);
new System.ComponentModel.AmbientValueAttribute : double -> System.ComponentModel.AmbientValueAttribute
Public Sub New (value As Double)

參數

value
Double

這個屬性的值。

適用於

AmbientValueAttribute(Int16)

來源:
AmbientValueAttribute.cs
來源:
AmbientValueAttribute.cs
來源:
AmbientValueAttribute.cs

初始化 AmbientValueAttribute 類別的新執行個體,需指定其值為 16 位元帶正負號的整數。

public:
 AmbientValueAttribute(short value);
public AmbientValueAttribute (short value);
new System.ComponentModel.AmbientValueAttribute : int16 -> System.ComponentModel.AmbientValueAttribute
Public Sub New (value As Short)

參數

value
Int16

這個屬性的值。

適用於

AmbientValueAttribute(Int32)

來源:
AmbientValueAttribute.cs
來源:
AmbientValueAttribute.cs
來源:
AmbientValueAttribute.cs

初始化 AmbientValueAttribute 類別的新執行個體,需指定其值為 32 位元帶正負號的整數。

public:
 AmbientValueAttribute(int value);
public AmbientValueAttribute (int value);
new System.ComponentModel.AmbientValueAttribute : int -> System.ComponentModel.AmbientValueAttribute
Public Sub New (value As Integer)

參數

value
Int32

這個屬性的值。

適用於

AmbientValueAttribute(Int64)

來源:
AmbientValueAttribute.cs
來源:
AmbientValueAttribute.cs
來源:
AmbientValueAttribute.cs

初始化 AmbientValueAttribute 類別的新執行個體,需指定其值為 64 位元帶正負號的整數。

public:
 AmbientValueAttribute(long value);
public AmbientValueAttribute (long value);
new System.ComponentModel.AmbientValueAttribute : int64 -> System.ComponentModel.AmbientValueAttribute
Public Sub New (value As Long)

參數

value
Int64

這個屬性的值。

適用於

AmbientValueAttribute(Object)

來源:
AmbientValueAttribute.cs
來源:
AmbientValueAttribute.cs
來源:
AmbientValueAttribute.cs

初始化 AmbientValueAttribute 類別的新執行個體,需指定其值為物件。

public:
 AmbientValueAttribute(System::Object ^ value);
public AmbientValueAttribute (object value);
public AmbientValueAttribute (object? value);
new System.ComponentModel.AmbientValueAttribute : obj -> System.ComponentModel.AmbientValueAttribute
Public Sub New (value As Object)

參數

value
Object

這個屬性的值。

適用於

AmbientValueAttribute(Single)

來源:
AmbientValueAttribute.cs
來源:
AmbientValueAttribute.cs
來源:
AmbientValueAttribute.cs

初始化 AmbientValueAttribute 類別的新執行個體,需指定其值為單精確度浮點數。

public:
 AmbientValueAttribute(float value);
public AmbientValueAttribute (float value);
new System.ComponentModel.AmbientValueAttribute : single -> System.ComponentModel.AmbientValueAttribute
Public Sub New (value As Single)

參數

value
Single

這個屬性的值。

適用於

AmbientValueAttribute(String)

來源:
AmbientValueAttribute.cs
來源:
AmbientValueAttribute.cs
來源:
AmbientValueAttribute.cs

初始化 AmbientValueAttribute 類別的新執行個體,需指定其值為字串。

public:
 AmbientValueAttribute(System::String ^ value);
public AmbientValueAttribute (string value);
public AmbientValueAttribute (string? value);
new System.ComponentModel.AmbientValueAttribute : string -> System.ComponentModel.AmbientValueAttribute
Public Sub New (value As String)

參數

value
String

這個屬性的值。

適用於

AmbientValueAttribute(Type, String)

來源:
AmbientValueAttribute.cs
來源:
AmbientValueAttribute.cs
來源:
AmbientValueAttribute.cs

初始化 AmbientValueAttribute 類別的新執行個體,需指定值和型別。

public:
 AmbientValueAttribute(Type ^ type, System::String ^ value);
public AmbientValueAttribute (Type type, string value);
new System.ComponentModel.AmbientValueAttribute : Type * string -> System.ComponentModel.AmbientValueAttribute
Public Sub New (type As Type, value As String)

參數

type
Type

value 參數的 Type

value
String

這個屬性的值。

範例

下列程式代碼範例示範如何使用 AmbientValueAttribute 來強制執行名為 AlertForeColor之屬性的環境行為。 如需完整的程式代碼清單,請參閱如何:在 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

適用於