UserScopedSettingAttribute 類別

定義

指定應用程式設定群組或屬性,其包含應用程式之每個使用者的不同值。 此類別無法獲得繼承。

public ref class UserScopedSettingAttribute sealed : System::Configuration::SettingAttribute
[System.AttributeUsage(System.AttributeTargets.Property)]
public sealed class UserScopedSettingAttribute : System.Configuration.SettingAttribute
[<System.AttributeUsage(System.AttributeTargets.Property)>]
type UserScopedSettingAttribute = class
    inherit SettingAttribute
Public NotInheritable Class UserScopedSettingAttribute
Inherits SettingAttribute
繼承
UserScopedSettingAttribute
屬性

範例

下列程式碼範例示範如何使用 UserScopedSettingAttribute 套用至包裝函式類別的所有四個屬性 FormSettings ,其衍生自 ApplicationSettingsBase 類別。 這個類別用來保存表單的位置、大小、背景色彩和文字。 完整的程式碼範例會列在類別概觀中 ApplicationSettingsBase

//Application settings wrapper class
ref class FormSettings sealed: public ApplicationSettingsBase
{
public:
    [UserScopedSettingAttribute()]
    property String^ FormText
    {
        String^ get()
        {
            return (String^)this["FormText"];
        }
        void set( String^ value )
        {
            this["FormText"] = value;
        }
    }

public:
    [UserScopedSettingAttribute()]
    [DefaultSettingValueAttribute("0, 0")]
    property Point FormLocation
    {
        Point get()
        {
            return (Point)(this["FormLocation"]);
        }
        void set( Point value )
        {
            this["FormLocation"] = value;
        }
    }

public:
    [UserScopedSettingAttribute()]
    [DefaultSettingValueAttribute("225, 200")]
    property Size FormSize
    {
        Size get()
        {
            return (Size)this["FormSize"];
        }
        void set( Size value )
        {
            this["FormSize"] = value;
        }
    }

public:
    [UserScopedSettingAttribute()]
    [DefaultSettingValueAttribute("LightGray")]
    property Color FormBackColor
    {
        Color get()
        {
            return (Color)this["FormBackColor"];
        }
        void set(Color value)
        {
            this["FormBackColor"] = value;
        }
    }

};
//Application settings wrapper class
sealed class FormSettings : ApplicationSettingsBase
{
    [UserScopedSettingAttribute()]
    public String FormText
    {
        get { return (String)this["FormText"]; }
        set { this["FormText"] = value; }
    }

    [UserScopedSettingAttribute()]
    [DefaultSettingValueAttribute("0, 0")]
    public Point FormLocation
    {
        get { return (Point)(this["FormLocation"]); }
        set { this["FormLocation"] = value; }
    }

    [UserScopedSettingAttribute()]
    [DefaultSettingValueAttribute("225, 200")]
    public Size FormSize
    {
        get { return (Size)this["FormSize"]; }
        set { this["FormSize"] = value; }
    }

    [UserScopedSettingAttribute()]
    [DefaultSettingValueAttribute("LightGray")]
    public Color FormBackColor
    {
        get { return (Color)this["FormBackColor"]; }
        set { this["FormBackColor"] = value; }
    }
}
'Application settings wrapper class. This class defines the settings we intend to use in our application.
NotInheritable Class FormSettings
    Inherits ApplicationSettingsBase

    <UserScopedSettingAttribute()> _
    Public Property FormText() As String
        Get
            Return CStr(Me("FormText"))
        End Get
        Set(ByVal value As String)
            Me("FormText") = value
        End Set
    End Property

    <UserScopedSettingAttribute(), DefaultSettingValueAttribute("0, 0")> _
    Public Property FormLocation() As Point
        Get
            Return CType(Me("FormLocation"), Point)
        End Get
        Set(ByVal value As Point)
            Me("FormLocation") = value
        End Set
    End Property

    <UserScopedSettingAttribute(), DefaultSettingValueAttribute("225, 200")> _
    Public Property FormSize() As Size
        Get
            Return CType(Me("FormSize"), Size)
        End Get
        Set(ByVal value As Size)
            Me("FormSize") = value
        End Set
    End Property

    <UserScopedSettingAttribute(), DefaultSettingValueAttribute("LightGray")> _
    Public Property FormBackColor() As Color
        Get
            Return CType(Me("FormBackColor"), Color)
        End Get
        Set(ByVal value As Color)
            Me("FormBackColor") = value
        End Set
    End Property
End Class

備註

應用程式設定屬性的範圍是以應用程式或使用者層級為基礎。 如類別所示,應用程式範圍屬性會將統一值呈現給應用程式的所有使用者,而使用者範圍屬性則具有應用程式的每個使用者專用值。

UserScopedSettingAttribute表示屬性應該視為使用者層級設定,而且應該由設定提供者據以做出適當的儲存體決策。

每個應用程式設定屬性都需要範圍屬性。 如果屬性未套用至 ApplicationScopedSettingAttributeUserScopedSettingAttribute ,則設定提供者會忽略該屬性 - 它不會序列化。 不過,將這兩個屬性套用至相同的設定屬性是不正確。 這類嘗試會導致 ConfigurationErrorsException 擲回 。

建構函式

UserScopedSettingAttribute()

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

屬性

TypeId

在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。

(繼承來源 Attribute)

方法

Equals(Object)

傳回值,這個值指出此執行個體是否與指定的物件相等。

(繼承來源 Attribute)
GetHashCode()

傳回這個執行個體的雜湊碼。

(繼承來源 Attribute)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
IsDefaultAttribute()

在衍生類別中覆寫時,表示這個執行個體的值是衍生類別的預設值。

(繼承來源 Attribute)
Match(Object)

在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

明確介面實作

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

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。

(繼承來源 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取物件的類型資訊,可以用來取得介面的類型資訊。

(繼承來源 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。

(繼承來源 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開的屬性和方法的存取權。

(繼承來源 Attribute)

適用於

另請參閱