TextSelection.Text (Propiedad)

Actualización: noviembre 2007

Establece u obtiene el texto seleccionado.

Espacio de nombres:  EnvDTE
Ensamblado:  EnvDTE (en EnvDTE.dll)

Sintaxis

Default Property Text As String

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)

Valor de propiedad

Tipo: System.String

Una cadena que representa el texto seleccionado.

Comentarios

La propiedad Text es la propiedad predeterminada para el objeto TextSelection.

Cuando se lee la propiedad Text, se devuelve el texto correspondiente al texto seleccionado y la selección propiamente dicha permanece inalterada.

Cuando se establece la propiedad Text, el valor de Text se inserta delante del texto seleccionado y después se contrae, de forma similar a lo que sucede cuando se pega texto en un documento. Observe que esta propiedad se comporta exactamente igual que cuando el editor está en modo de inserción (es decir, no de sobrescritura). El texto situado después del carácter 128 se trunca.

Si la propiedad Mode del objeto TextSelection se establece en Column, al establecer la propiedad Text se genera un error.

Ejemplos

Este ejemplo sólo funciona en Visual Studio .NET 2003. Para obtener más información, vea Cómo: Migrar código que crea proyectos mediante plantillas.

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

Permisos

Vea también

Referencia

TextSelection (Interfaz)

TextSelection (Miembros)

EnvDTE (Espacio de nombres)

Otros recursos

Cómo: Compilar y ejecutar los ejemplos de código del modelo de objetos de automatización