Click to Rate and Give Feedback
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
Visual Studio Automation and Extensibility 
DTE Properties Collections 

The environment-level properties are organized into categories that correspond to the hierarchy displayed in the Options dialog box. To see the Options dialog box, on the Tools menu, click Options. For the sake of simplicity, this topic refers to this dialog box as the Tools Options dialog box. For example, DTE.Properties("TextEditor", "Basic") represents the settings in the Basic node within the Text Editor node in the Tools Options dialog box. Many times, the settings in the dialog boxes are also represented by properties. For example, one setting in the Tabs, Basic, Text Editor, Options dialog box is Tab size. This is represented by the TabSize and TabSize properties. Each property item has one or more values, represented by the Value property. For information about how to change options values by using properties, see Controlling Tools Options Settings.

The topics in the See Also section below list the predefined categories that come with Visual Studio. However, Visual Studio packages can add their own categories (Tools Options pages), and you can create your own custom Tools Options pages.

NoteNote

Some property pages in the Options dialog box do not support automation. The property pages that do support automation are listed in Determining Names of Property Items in Tools Options Pages.

The same Properties collection object can be accessed in different locations. For example, a properties collection for fonts and colors might be accessed with either DTE.Properties("Environment", "FontsAndColors") or DTE.Properties("TextEditor", "FontsAndColors").

The following example illustrates how to view all accessible property items in the General, C#, Text Editor, Options dialog box. Note that in code, the "C#" node must be represented as "CSharp." For more information about how to run the Add-in example, see How to: Compile and Run the Automation Object Model Code Examples.

Visual Basic
' 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
C#
// 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); 
}

A slight modification to the previous code allows you to view the options of a nested node, in the following case, the Formatting, C#, Text Editor, Options page. You do this by changing the second Properties parameter value to the options you want to view or change, such as DTE.Properties("TextEditor", "Basic - Tabs"), or DTE.Properties("Environment", "Help - Online"). The values to use are listed at the beginning of this topic.

This case uses "CSharp - Formatting" to view the Formatting options settings for the C# Text Editor.

Visual Basic
' 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
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker