TextRange.Contains(TextPointer) Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Verifica se uma posição (especificada por um TextPointer) está localizada dentro da seleção atual.
public:
bool Contains(System::Windows::Documents::TextPointer ^ textPointer);
public bool Contains(System.Windows.Documents.TextPointer textPointer);
member this.Contains : System.Windows.Documents.TextPointer -> bool
Public Function Contains (textPointer As TextPointer) As Boolean
Parâmetros
- textPointer
- TextPointer
Uma posição para testar a inclusão na seleção atual.
Devoluções
true se a posição especificada estiver dentro da seleção atual; caso contrário, false.
Exceções
Ocorre quando textPointer não está no mesmo documento da seleção atual.
Exemplos
O exemplo a seguir demonstra o uso do Contains método.
// 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;
}
}
' This method returns true if two specified selections overlap, including when the
' end of one selection serves as the beginning of the other.
Private Function DoSelectionsOverlap(ByVal selection1 As TextRange, ByVal selection2 As TextRange) As Boolean
' Is either end of selection2 contained by selection1?
If selection1.Contains(selection2.Start) OrElse selection1.Contains(selection2.End) Then
' If so, the selections overlap.
Return True
' If not, selection2 may still entirely contain selection1.
' Is either end of selection1 contained by seleciotn2?
ElseIf selection2.Contains(selection1.Start) OrElse selection2.Contains(selection1.End) Then
' 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
End If
End Function
Observações
As posições em cada extremidade da seleção atual (indicadas por Start e End) são consideradas parte da seleção atual.