Propriedade TextSelection.Text

Define ou obtém o texto selecionado.

Namespace:  EnvDTE
Assembly:  EnvDTE (em EnvDTE.dll)

Sintaxe

'Declaração
Default Property Text As String
    Get
    Set
string this { get; set; }
property String^ default {
    String^ get ();
    void set (String^ value);
}
abstract Text : string with get, set
function get Text () : String
function set Text (value : String)

Valor de propriedade

Tipo: System.String
Uma seqüência de caracteres que representa o texto selecionado.

Comentários

O Text é a propriedade padrão para o TextSelection objeto.

Quando o Text a propriedade é leitura, o texto no texto selecionado é retornado e a seleção em si permanece inalterada.

Quando o Text for definida, o valor de Text é inserido na frente do texto selecionado e, em seguida, recolhido, semelhante ao que acontece quando o texto é colado no documento. Observe que essa propriedade se comporta exatamente como apareceria quando o editor está no modo de inserção (ou seja, nonovertype). Qualquer texto após o caractere de 128th será truncado.

Se a Mode propriedade da TextSelection objeto é definido como Column, em seguida, definindo a Text propriedade gera um erro.

Exemplos

Este exemplo funciona apenas em Visual Studio.NET 2003. Para obter mais informações, consulte 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";
}

Segurança do .NET Framework

Consulte também

Referência

TextSelection Interface

Namespace EnvDTE

Outros recursos

Como: compilar e Executar a automação de exemplos de Código do modelo de objeto