TextSelection.Text-Eigenschaft

Setzt oder ruft die Textauswahl ab.

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

Syntax

'Declaration
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)

Eigenschaftswert

Typ: String
Eine Zeichenfolge, die die Textauswahl darstellt.

Hinweise

Die Text-Eigenschaft ist die Standardeigenschaft für das TextSelection-Objekt.

Wenn die Text-Eigenschaft gelesen wird, wird der Text in der Textauswahl zurückgegeben, und die Auswahl selbst ist unverändert.

Wenn die Eigenschaft Text festgelegt ist, wird der Wert von Text vor der Textauswahl eingefügt und reduziert dann, ähnlich, was geschieht, wenn Text in ein Dokument eingefügt wird. Das Verhalten dieser Eigenschaft entspricht dem Verhalten des Editors im Einfügemodus (d. h. nicht überschreiben). Text nach dem 128. Zeichen wird abgeschnitten.

Wenn der Wert der Mode-Eigenschaft des TextSelection-Objekts Column lautet, wird durch Festlegen der Text-Eigenschaft ein Fehler verursacht.

Beispiele

Für dieses Beispiel ist Visual Studio .NET 2003 erforderlich. Weitere Informationen finden Sie unter Migrating 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-Sicherheit

Siehe auch

Referenz

TextSelection Schnittstelle

EnvDTE-Namespace

Weitere Ressourcen

Gewusst wie: Kompilieren und Ausführen der Codebeispiele für das Automatisierungsobjektmodell