Proprietà TextSelection.Text

Imposta o ottiene il testo selezionato.

Spazio dei nomi:  EnvDTE
Assembly:  EnvDTE (in EnvDTE.dll)

Sintassi

'Dichiarazione
Default Property Text As String
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)

Valore proprietà

Tipo: System.String
Stringa che rappresenta il testo selezionato.

Note

Text la proprietà è la proprietà predefinita per TextSelection oggetto.

quando Text la proprietà viene letta, il testo del testo selezionato viene restituito e la selezione stessa resterà invariata.

quando Text la proprietà è impostata, il valore di Text viene inserita davanti al testo selezionato e quindi è compresso, simile a quello che accade quando il testo viene inserito in un documento.Si noti che questa proprietà si comporta come quando l'editor è in modalità di inserimento (ovvero nonovertype).Qualsiasi testo dopo il 128th carattere viene troncato.

se Mode proprietà di TextSelection l'oggetto è impostato su Column, quindi impostare Text la proprietà genera un errore.

Esempi

Questo esempio funziona solo in Visual Studio .NET 2003.Per ulteriori informazioni, vedere Esegue la migrazione codice che crea i progetti utilizzando i modelli.

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";
}

Sicurezza di .NET Framework

Vedere anche

Riferimenti

TextSelection Interfaccia

Spazio dei nomi EnvDTE

Altre risorse

Procedura: compilare ed eseguire gli esempi di codice del modello a oggetti di automazione