本文整理汇总了C#中System.Windows.Automation.TextPattern.FontNameAttribute字段的典型用法代码示例。如果您正苦于以下问题:C# TextPattern.FontNameAttribute字段的具体用法?C# TextPattern.FontNameAttribute怎么用?C# TextPattern.FontNameAttribute使用的例子?那么恭喜您, 这里精选的字段代码示例或许可以为您提供帮助。
在下文中一共展示了TextPattern.FontNameAttribute字段的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetFontNameAttribute
/// -------------------------------------------------------------------
/// <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());
}
}
}