TextPatternRange.ExpandToEnclosingUnit(TextUnit) メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
指定した TextUnitにテキスト範囲を展開します。
public:
void ExpandToEnclosingUnit(System::Windows::Automation::Text::TextUnit unit);
public void ExpandToEnclosingUnit(System.Windows.Automation.Text.TextUnit unit);
member this.ExpandToEnclosingUnit : System.Windows.Automation.Text.TextUnit -> unit
Public Sub ExpandToEnclosingUnit (unit As TextUnit)
パラメーター
- unit
- TextUnit
テキスト単位。
例
private void ExpandSelection(AutomationElement target)
{
// Specify the control type we're looking for, in this case 'Document'
PropertyCondition cond = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document);
// target --> The root AutomationElement.
AutomationElement textProvider = target.FindFirst(TreeScope.Descendants, cond);
TextPattern textpatternPattern = textProvider.GetCurrentPattern(TextPattern.Pattern) as TextPattern;
if (textpatternPattern == null)
{
Console.WriteLine("Root element does not contain a descendant that supports TextPattern.");
return;
}
TextPatternRange[] currentSelection = textpatternPattern.GetSelection();
// Expand selection to include entire document
currentSelection[0].ExpandToEnclosingUnit(TextUnit.Document);
}
Private Sub ExpandSelection(ByVal target As AutomationElement)
' Specify the control type we're looking for, in this case 'Document'
Dim cond As PropertyCondition = New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document)
' target --> The root AutomationElement.
Dim textProvider As AutomationElement = target.FindFirst(TreeScope.Descendants, cond)
Dim textpatternPattern As TextPattern = CType(textProvider.GetCurrentPattern(TextPattern.Pattern), TextPattern)
If (textpatternPattern Is Nothing) Then
Console.WriteLine("Root element does not contain a descendant that supports TextPattern.")
Return
End If
Dim currentSelection As TextPatternRange() = textpatternPattern.GetSelection()
currentSelection(0).ExpandToEnclosingUnit(TextUnit.Document)
End Sub
注釈
範囲が既に指定した単位の正確な数量である場合は、変更されません。
ExpandToEnclosingUnit メソッドが正常に実行されるためには、一連のアクションがバックグラウンドで実行されます。
テキスト範囲は正規化されます。つまり、テキスト範囲は Start エンドポイントで縮小された範囲に折りたたまれるため、 End エンドポイントは余分になります。 この手順は、テキスト範囲が
unit境界にまたがる状況であいまいさを取り除くために必要です。たとえば、"{The U}RL https://www.microsoft.com/ is embedded in text" ("{" と "}" はテキスト範囲のエンドポイントです)。結果として得られる範囲は、 DocumentRange 内で、要求された
unit境界の先頭に向かって後方に移動されます。範囲は、要求された数のDocumentRange境界によって
unit内で前方または後方に移動されます。その後、要求された 1 つのEnd境界によって
unitエンドポイントを移動することで、範囲が縮退した範囲の状態から拡張されます。
Move() と ExpandToEnclosingUnit() に対してテキスト範囲を調整する方法の例
Note
これらの手順は、スクリーン リーダーが挿入ポイントまたは任意の仮想カーソル位置で単語、文、または段落全体を読み上げるのが一般的であるため、必要です。
ExpandToEnclosingUnit は、非表示のテキストと表示されるテキストの両方を尊重します。 UI オートメーション クライアントは、IsHiddenAttributeでテキストの表示を確認できます。
ExpandToEnclosingUnitは、指定されたTextUnitがコントロールでサポートされていない場合にサポートされる次の最大TextUnitに遅延します。
最小単位から最大値までの順序を次に示します。