AmbientValueAttribute 建構函式

定義

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

多載

名稱 Description
AmbientValueAttribute(Boolean)

初始化一個新的類別實例 AmbientValueAttribute ,給定一個布林值。

AmbientValueAttribute(Byte)

初始化該類別的新實例 AmbientValueAttribute ,給定一個 8 位元無符號整數作為值。

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.cs
來源:
AmbientValueAttribute.cs

初始化一個新的類別實例 AmbientValueAttribute ,給定一個布林值。

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.cs
來源:
AmbientValueAttribute.cs

初始化該類別的新實例 AmbientValueAttribute ,給定一個 8 位元無符號整數作為值。

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.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.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.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.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.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.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.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.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.cs
來源:
AmbientValueAttribute.cs

初始化該類別的新實例 AmbientValueAttribute ,給定值及其型別。

public:
 AmbientValueAttribute(Type ^ type, System::String ^ value);
public AmbientValueAttribute(Type type, string value);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Generic TypeConverters may require the generic types to be annotated. For example, NullableConverter requires the underlying type to be DynamicallyAccessedMembers All.")]
public AmbientValueAttribute(Type type, string value);
new System.ComponentModel.AmbientValueAttribute : Type * string -> System.ComponentModel.AmbientValueAttribute
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Generic TypeConverters may require the generic types to be annotated. For example, NullableConverter requires the underlying type to be DynamicallyAccessedMembers All.")>]
new System.ComponentModel.AmbientValueAttribute : Type * string -> System.ComponentModel.AmbientValueAttribute
Public Sub New (type As Type, value As String)

參數

type
Type

參數的Typevalue

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 =>
        _alertForeColorValue == Color.Empty &&
        Parent != null
            ? Parent.ForeColor
            : _alertForeColorValue;

    set => _alertForeColorValue = value;
}

// This method is used by designers to enable resetting the
// property to its default value.
public void ResetAlertForeColor() =>
    AlertForeColor = s_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.
bool ShouldSerializeAlertForeColor() =>
    _alertForeColorValue != s_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

適用於