DTE 属性集合

更新:2007 年 11 月

环境级属性被组织到与“选项”对话框中显示的层次结构相对应的类别中。若要查看“选项”对话框,请在“工具”菜单上单击“选项”。为了简便,该主题将此对话框称为“工具选项”对话框。例如,DTE.Properties("TextEditor", "Basic") 表示“工具选项”对话框中“文本编辑器”节点内的“基本”节点中的设置。许多情况下,此对话框中的设置也可以用属性表示。例如,“选项卡”、“基本”、“文本编辑器”和“选项”对话框中的一项设置为“选项卡大小”。该设置由 TabSizeTabSize 属性表示。每个属性项具有一个或多个值,由 Value 属性表示。有关如何使用属性更改选项值的信息,请参见控制选项设置

下面的“另请参见”部分中的主题列出了随 Visual Studio 一起提供的预定义类别。但是,Visual Studio 程序包可以添加它们自己的类别(“工具选项”页),您也可以创建个性化的自定义“工具选项”页。

ms165641.alert_note(zh-cn,VS.90).gif说明:

“选项”对话框中的某些属性页不支持自动化。确定选项页中属性项的名称中列出了支持自动化的属性页。

可在不同位置访问相同的 Properties 集合对象。例如,字体和颜色的属性集合可以通过 DTE.Properties("Environment", "FontsAndColors") 或 DTE.Properties("TextEditor", "FontsAndColors") 访问。

示例

下面的示例演示如何查看“常规”、“C#”、“文本编辑器”和“选项”对话框中的所有可访问属性项。请注意,在节点中,“C#”节点必须表示为“CSharp”。有关如何运行外接程序示例的更多信息,请参见如何:编译和运行自动化对象模型代码示例

' 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 - 格式设置”查看 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

请参见

任务

如何:创建自定义工具选项页

概念

控制选项设置

确定选项页中属性项的名称

“选项”页 ->“环境”节点属性

“选项”页 ->“字体和颜色”节点属性

“选项”页 ->“文本编辑器”节点属性

参考

“选项”对话框 ->“文本编辑器”->“C#”->“格式设置”