TextRange.Contains(TextPointer) Método

Definición

Comprueba si una posición (especificada por TextPointer) se encuentra dentro de la selección actual.

C#
public bool Contains (System.Windows.Documents.TextPointer textPointer);

Parámetros

textPointer
TextPointer

Posición que se comprueba para su inclusión en la selección actual.

Devoluciones

Boolean

true si la posición especificada se encuentra dentro de la selección actual; de lo contrario, false.

Excepciones

Se produce cuando textPointer no está en el mismo documento que la selección actual.

Ejemplos

En el siguiente ejemplo se muestra el uso del método Contains.

C#
// This method returns true if two specified selections overlap, including when the
// end of one selection serves as the beginning of the other.
bool DoSelectionsOverlap(TextRange selection1, TextRange selection2)
{
    // Is either end of selection2 contained by selection1?
    if (selection1.Contains(selection2.Start) || selection1.Contains(selection2.End))
    {
        // If so, the selections overlap.
        return true;
    }
    // If not, selection2 may still entirely contain selection1.
    // Is either end of selection1 contained by seleciotn2?
    else if (selection2.Contains(selection1.Start) || selection2.Contains(selection1.End))
    {
        // If so, the selections overlap.
        return true;
    }
    // If neither selection contains the begging or end of the other selection, 
    //the selections do not overlap.
    else
    {
        return false;
    }
}

Comentarios

Las posiciones al final de la selección actual (indicadas por Start y End) se consideran parte de la selección actual.

Se aplica a

Producto Versiones
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Windows Desktop 3.0, 3.1, 5, 6, 7