TextSelection.Text Property
Sets or gets the selected text.
Namespace: EnvDTE
Assembly: EnvDTE (in EnvDTE.dll)
Syntax
'Declaration
Default Property Text As String
'Usage
Dim instance As TextSelection
Dim value As String
value = instance
instance = value
string this { get; set; }
property String^ default {
String^ get ();
void set (String^ value);
}
function get Text () : String
function set Text (value : String)
Property Value
Type: System.String
A string representing the selected text.
Remarks
The Text property is the default property for the TextSelection object.
When the Text property is read, the text in the selected text is returned, and the selection itself is unchanged.
When the Text property is set, the value of Text is inserted in front of the selected text and then collapsed, similar to what happens when text is pasted into a document. Note that this property behaves just as it would when the editor is in insert (that is, nonovertype) mode. Any text after the 128th character is truncated.
If the Mode property of the TextSelection object is set to Column, then setting the Text property generates an error.
Examples
This example works only in Visual Studio .NET 2003. For more information, see How to: Migrate Code that Creates Projects by Using Templates.
Sub TextExample(ByVal dte As DTE)
' NOTE: This examples requires a reference to the
' VSLangProj namespace.
' Create a new solution.
Dim soln As Solution = dte.Solution
Dim solnName As String = "NewSolution.sln"
Dim tempPath As String = System.IO.Path.GetTempPath()
soln.Create(tempPath, solnName)
' Create a new Visual Basic Console Application project.
Dim templatePath As String =
dte.Solution.TemplatePath(PrjKind.prjKindVBProject)
templatePath &= "ConsoleApplication.vsz"
Dim projName As String = "NewProject"
soln.AddFromTemplate(templatePath, tempPath & projName, projName)
Dim proj As Project = soln.Item(1)
' Add a comment to Module1.vb.
Dim item As ProjectItem = proj.ProjectItems.Item("Module1.vb")
Dim sel As TextSelection = CType(item.Document.Selection,
TextSelection)
sel.StartOfDocument()
sel.NewLine()
sel.LineUp()
sel.Text = "' New comment" & vbCrLf
End Sub
public void TextExample(DTE dte)
{
// NOTE: This examples requires a reference to the
// VSLangProj namespace.
// Create a new solution.
Solution soln = dte.Solution;
string solnName = "NewSolution.sln";
string tempPath = System.IO.Path.GetTempPath();
soln.Create(tempPath, solnName);
// Create a new C# Console Application project.
string templatePath =
dte.Solution.get_TemplatePath(PrjKind.prjKindCSharpProject);
templatePath += "CSharpConsole.vsz";
string projName = "Project1";
soln.AddFromTemplate(templatePath, tempPath + projName,
projName, false);
Project proj = soln.Item(1);
// Add a comment to Class1.cs.
ProjectItem item = proj.ProjectItems.Item("Class1.cs");
TextSelection sel = (TextSelection)item.Document.Selection;
sel.StartOfDocument(false);
sel.NewLine(1);
sel.LineUp(false, 1);
sel.Text = "// New comment\n";
}
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.
See Also
Reference
Other Resources
How to: Compile and Run the Automation Object Model Code Examples