TextPattern.FontNameAttribute 欄位
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
識別文字範圍的 FontName
屬性。
public: static initonly System::Windows::Automation::AutomationTextAttribute ^ FontNameAttribute;
public static readonly System.Windows.Automation.AutomationTextAttribute FontNameAttribute;
staticval mutable FontNameAttribute : System.Windows.Automation.AutomationTextAttribute
Public Shared ReadOnly FontNameAttribute As AutomationTextAttribute
欄位值
範例
下列範例示範如何取得 Microsoft 記事本中文字範圍的屬性值。
注意
Microsoft 記事本僅做為文字提供者。 Microsoft 記事本不保證支援所要求的屬性值。
/// -------------------------------------------------------------------
/// <summary>
/// Outputs the FontNameAttribute value for a range of text.
/// </summary>
/// <param name="targetTextElement">
/// The AutomationElment that represents a text control.
/// </param>
/// -------------------------------------------------------------------
private void GetFontNameAttribute(AutomationElement targetTextElement)
{
TextPattern textPattern =
targetTextElement.GetCurrentPattern(TextPattern.Pattern) as TextPattern;
if (textPattern == null)
{
// Target control doesn't support TextPattern.
return;
}
// If the target control doesn't support selection then return.
// Otherwise, get the text attribute for the selected text.
// If there are currently no selections then the text attribute
// will be obtained from the insertion point.
TextPatternRange[] textRanges;
if (textPattern.SupportedTextSelection == SupportedTextSelection.None)
{
return;
}
else
{
textRanges = textPattern.GetSelection();
}
foreach (TextPatternRange textRange in textRanges)
{
Object textAttribute =
textRange.GetAttributeValue(
TextPattern.FontNameAttribute);
if (textAttribute == TextPattern.MixedAttributeValue)
{
// Returns MixedAttributeValue if the value of the
// specified attribute varies over the text range.
Console.WriteLine("Mixed fonts.");
}
else if (textAttribute == AutomationElement.NotSupported)
{
// Returns NotSupported if the specified attribute is
// not supported by the provider or the control.
Console.WriteLine(
"FontNameAttribute not supported by provider.");
}
else
{
Console.WriteLine(textAttribute.ToString());
}
}
}
''' -------------------------------------------------------------------
''' <summary>
''' Outputs the FontNameAttribute value for a range of text.
''' </summary>
''' <param name="targetTextElement">
''' The AutomationElement. that represents the text provider.
''' </param>
''' -------------------------------------------------------------------
Private Sub GetFontNameAttribute( _
ByVal targetTextElement As AutomationElement)
Dim targetTextPattern As TextPattern = _
DirectCast(targetTextElement.GetCurrentPattern( _
TextPattern.Pattern), TextPattern)
If (targetTextPattern Is Nothing) Then
' Target control doesn't support TextPattern.
Return
End If
' If the target control doesn't support selection then return.
' Otherwise, get the text attribute for the selected text.
' If there are currently no selections then the text attribute
' will be obtained from the insertion point.
Dim textRanges() As TextPatternRange
If (targetTextPattern.SupportedTextSelection = SupportedTextSelection.None) Then
Return
Else
textRanges = targetTextPattern.GetSelection()
End If
Dim textRange As TextPatternRange
For Each textRange In textRanges
Dim textAttribute As Object = _
textRange.GetAttributeValue( _
TextPattern.FontNameAttribute)
If (textAttribute = TextPattern.MixedAttributeValue) Then
' Returns MixedAttributeValue if the value of the
' specified attribute varies over the text range.
Console.WriteLine("Mixed fonts.")
ElseIf (textAttribute = AutomationElement.NotSupported) Then
' Returns NotSupported if the specified attribute is
' not supported by the provider or the control.
Console.WriteLine( _
"FontNameAttribute not supported by provider.")
Else
Console.WriteLine(textAttribute.ToString())
End If
Next
End Sub
備註
此屬性的範例值包括 「Arial Black」 和 「Arial Narrow」。
此屬性的值未當地語系化。
消費者介面自動化用戶端應用程式會使用此識別碼。 消費者介面自動化提供者應該使用 中的 TextPatternIdentifiers 對等欄位。
消費者介面自動化用戶端藉由呼叫 GetAttributeValue 取得 屬性的值。
此屬性的值的類型為 String 。 預設值為 empty string
。