共用方式為


DTE 屬性集合

更新:2007 年 11 月

環境層級的屬性會依據 [選項] 對話方塊中所顯示的階層架構組成不同的分類。若要查看 [選項] 對話方塊,請按一下 [工具] 功能表上的 [選項]。為了簡單起見,本主題將此對話方塊稱為 [工具選項] 對話方塊。例如,在 [工具選項] 對話方塊中,DTE.Properties("TextEditor", "Basic") 表示 [文字編輯器] 節點內 [基本] 節點中的設定。對話方塊中的設定也經常會用屬性來表示。例如,在 [選項] 對話方塊、[文字編輯器]、[基本]、[定位點] 中,有一個設定為 [定位點大小]。這個設定是以 TabSizeTabSize 屬性來表示。每個屬性項目有一或多個值,分別以 Value 屬性來表示。如需如何使用屬性變更選項值的詳細資訊,請參閱控制選項設定

下面<請參閱>一節中的主題會列出 Visual Studio 中預先定義的分類。但是,Visual Studio 套件可以加入自己的分類 ([工具選項] 頁),而您也可以建立自訂的 [工具選項] 頁。

注意事項:

[選項] 對話方塊中有些屬性頁並不支援 Automation。支援 Automation 的屬性頁會列在在選項頁中決定屬性項目的名稱中。

相同的 Properties 集合物件 (Collection Object),可以從不同的位置存取。例如,字型和色彩的屬性集合可以用 DTE.Properties("Environment", "FontsAndColors") 或 DTE.Properties("TextEditor", "FontsAndColors") 來存取。

範例

在下列範例中,會說明如何在 [選項] 對話方塊、[文字編輯器]、[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 - Tabs") 或 DTE.Properties("Environment", "Help - Online")。要使用的值列在本主題的開頭。

在本範例中,會使用 "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 - Formatting")
    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:建立自訂工具選項頁

概念

控制選項設定

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

環境節點屬性、選項頁

字型和色彩節點屬性、選項頁

文字編輯器節點屬性、選項頁

參考

選項對話方塊、文字編輯器、C#、格式