AmbientValueAttribute クラス
アセンブリ: System (system.dll 内)

<AttributeUsageAttribute(AttributeTargets.All)> _ Public NotInheritable Class AmbientValueAttribute Inherits Attribute
[AttributeUsageAttribute(AttributeTargets.All)] public sealed class AmbientValueAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::All)] public ref class AmbientValueAttribute sealed : public Attribute

コントロールのプロパティにアンビエント動作が適用される場合は、必ずこの属性が使用されます。アンビエント プロパティには Control.Font や Control.BackColor などがありますが、これらのプロパティは親プロパティに自身の値を照会します。
通常、ビジュアル デザイナは AmbientValueAttribute 属性を使用して、プロパティに永続的に適用する値を決定します。この値は、通常、プロパティに別のソースから値を取得させる働きをする値です。たとえば、Color.Empty は BackColor プロパティのアンビエント値として機能します。フォーム上にコントロールがあり、そのコントロールの BackColor プロパティがフォームの BackColor プロパティとは異なる色に設定されている場合、コントロールの BackColor を Color.Empty に設定することで、そのコントロールの BackColor プロパティをフォームと同じ値にリセットできます。

AmbientValueAttribute を使用して、AlertForeColor というプロパティのアンビエント動作を適用するコード例を次に示します。完全なコードの一覧については、「方法 : Windows フォーム コントロールに属性を適用する」を参照してください。
<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); }

System.Attribute
System.ComponentModel.AmbientValueAttribute


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- AmbientValueAttribute クラスのページへのリンク