DTE Properties Collections
The environment-level properties are organized into categories that correspond to the hierarchy that is displayed in the Options dialog box. For example, DTE.Properties("TextEditor", "Basic") represents the settings in the Basic node under the Text Editor node in the Options dialog box. Many of the settings on the pages in the dialog box are also represented by properties. For example, one setting on the Tabs page in the Basic node under the Text Editor node is Tab size. This setting is represented by the TabSize and TabSize properties. Every property item has one or more values, which are represented by the Value property. For information about how to change the values by using properties, see Controlling Options Settings.
The following documents list predefined categories of settings that are included in Visual Studio.
To add settings to an existing Options page, or to add a custom page to the Options dialog box, use the Visual Studio SDK. For more information, see the Development Tools Ecosystem Partner Portal Web site.
Note
Some pages in the Options dialog box do not support automation. For information about which property pages support automation, see Determining the Names of Property Items on Options Pages.
To open the Options dialog box in the integrated development environment (IDE), on the Tools menu, click Options.
Example
The following example illustrates how to view the accessible property items on the General page in the C# node under the Text Editor node in the Options dialog box. Notice 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.
' 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);
}
In the following example, which contains a slight modification to the previous example, you can view the settings of a nested node, in this case, the Formatting node in the C# node under the Text Editor node. To make the modification, change the value of the second Properties parameter to the setting you want to view or change, for example, DTE.Properties("TextEditor", "Basic-Specific"), or DTE.Properties("Environment", "ProjectsAndSolution"). The values to use are listed at the beginning of this document.
This case uses "CSharp - Formatting" to view the Formatting settings for the C# Text Editor.
' 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
See Also
Tasks
How to: Create Custom Options Pages