DTE 屬性集合

環境層級的屬性會依據 [選項] 對話方塊中所顯示的階層架構組成不同的分類。 例如,在 [選項] 對話方塊中,DTE.Properties("TextEditor", "Basic") 表示 [文字編輯器] 節點下 [基本] 節點中的設定。 對話方塊中頁面的許多設定也用屬性來表示。 例如,在 [文字編輯器] 節點下,[基本] 節點的 [定位點] 頁面中的一個設定式 [定位點大小] 這個設定是以 TabSizeTabSize 屬性來表示。 每個屬性項目有一或多個值,分別以 Value 屬性來表示。 如需如何使用屬性變更值的詳細資訊,請參閱控制選項設定

下列文件列出 Visual Studio 中所包含之設定的預先定義分類。

若要將設定加入至現有的 [選項] 頁,或是將自訂頁加入至 [選項] 對話方塊中,請使用 Visual Studio SDK。 如需詳細資訊,請參閱開發工具生態系統夥伴入口網站 (英文)。

注意事項注意事項

[選項] 對話方塊中有些頁面並不支援 Automation。 有關哪些屬性頁支援自動化的資訊,請參閱在選項頁中決定屬性項目的名稱.

若要開啟整合式開發環境 (IDE) 中的 [選項] 對話方塊,請按一下 [工具] 功能表上的 [選項]。

範例

下列範例說明如何在 [選項] 對話方塊之 [文字編輯器] 節點下方的 [C#] 節點中,檢視 [一般] 頁面上的可存取屬性項目。 請注意,在程式碼中 "C#" 節點必須以 "CSharp" 來表示。如需如何執行增益集 (Add-In) 範例的詳細資訊,請參閱 HOW TO:編譯和執行 Automation 物件模型程式碼範例

' Add-in code.
Public Sub OnConnection(ByVal application As Object, ByVal connectMode _
As Extensibility.ext_ConnectMode, ByVal addInInst As Object, ByRef _
custom As System.Array) Implements Extensibility.IDTExtensibility2.OnConnection

    applicationObject = CType(application, EnvDTE.DTE)
    addInInstance = CType(addInInst, EnvDTE.AddIn)
    ' Pass the applicationObject member variable to the code example.
    PropertiesExample (applicationObject)
    End Sub

Sub PropertiesExample(ByVal dte As DTE)
    ' Create and initialize a variable to represent the C# 
    ' text editor options page.
    Dim txtEdCS As EnvDTE.Properties = _
    DTE.Properties("TextEditor", "CSharp")
    Dim prop As EnvDTE.Property
    Dim msg As String

    ' Loop through each item in the C# text editor options page. 
    For Each prop In txtEdCS
        msg += ("PROP NAME: " & prop.Name & "   VALUE: " & _
        prop.Value) & vbCr
    Next
    MsgBox(msg)
End Sub
// Add-in code.
Using System.Windows.Forms;
public void OnConnection(object application,
 Extensibility.ext_ConnectMode connectMode, object addInInst,
 ref System.Array custom)
{
    applicationObject = (_DTE)application;
    addInInstance = (AddIn)addInInst;
    // Pass the applicationObject member variable to the code example.
    PropertiesExample((DTE)applicationObject); 
}

public void PropertiesExample( DTE dte ) 
{ 
    // Create and initialize a variable to represent the C# 
    // text editor options page.
    EnvDTE.Properties txtEdCS =
 dte.get_Properties( "TextEditor", "CSharp" ); 
    EnvDTE.Property prop = null; 
    string msg = null; 

    // Loop through each item in the C# text editor options page. 
    foreach ( EnvDTE.Property temp in txtEdCS ) 
    { 
        prop = temp; 
        msg += ( "PROP NAME: " + prop.Name + "   VALUE: " 
+ prop.Value ) + "\n"; 
    }
    MessageBox.Show( msg); 
}

下列範例包含稍做修改的上一個範例,您可以看到巢狀節點的設定,在此範例中,該設定在 [文字編輯器] 節點下,[C# ] 節點中的 [格式] 節點內。 若要進行修改,請將第二個 Properties 參數值變更為您要檢視或變更的設定,例如 DTE.Properties("TextEditor", "Basic-Specific") 或 DTE.Properties("Environment", "ProjectsAndSolution")。 要使用的值列在本文件的開頭。

這個案例會使用 "CSharp - Formatting" 來檢視 C# 文字編輯器的 [格式] 設定。

' Add-in code.
Sub PropertiesExample()
    ' Create and initialize a variable to represent the C# 
    ' Formatting text editor options page.
    Dim txtEdCSFormat As EnvDTE.Properties = _
    DTE.Properties("TextEditor", "CSharp-Specific")
    Dim prop As EnvDTE.Property
    Dim msg As String

    ' Loop through each item in the C# Formatting Options page. 
    For Each prop In txtEdCSFormat
        msg += ("PROP NAME: " & prop.Name & "   VALUE: " & _
        prop.Value) & vbCr
    Next
    MsgBox(msg)
End Sub

請參閱

工作

HOW TO:建立自訂選項頁面

概念

控制選項設定

在選項頁中決定屬性項目的名稱