TextPattern.FontWeightAttribute 字段

定义

标识文本范围的 FontWeight 特性。Identifies the FontWeight attribute of a text range.

public: static initonly System::Windows::Automation::AutomationTextAttribute ^ FontWeightAttribute;
public static readonly System.Windows.Automation.AutomationTextAttribute FontWeightAttribute;
 staticval mutable FontWeightAttribute : System.Windows.Automation.AutomationTextAttribute
Public Shared ReadOnly FontWeightAttribute As AutomationTextAttribute 

字段值

示例

下面的示例演示如何获取 Microsoft Notepad 中文本范围的属性值。The following example shows how to obtain an attribute value for a range of text in Microsoft Notepad.

备注

仅出于举例目的,Microsoft Notepad 用作文本提供程序。Microsoft Notepad is used as the text provider for example purposes only. 不保证 Microsoft 记事本支持所请求的属性值。Microsoft Notepad is not guaranteed to support the attribute value being requested.

private void GetFontWeightAttribute()
{
    // Start application.
    Process p = Process.Start("Notepad.exe", "text.txt");

    // target --> The root AutomationElement.
    AutomationElement target = AutomationElement.FromHandle(p.MainWindowHandle);

    // Specify the control type we're looking for, in this case 'Document'
    PropertyCondition cond = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document);

    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;
    }

    Object oAttribute = textpatternPattern.DocumentRange.GetAttributeValue(TextPattern.FontWeightAttribute);
    if (oAttribute == TextPattern.MixedAttributeValue)
    {
        Console.WriteLine("Mixed font weights.");
    }
    else
    {
        Console.WriteLine(oAttribute.ToString());
    }
}
Private Sub GetFontWeightAttribute()
    ' Start application.
    Dim p As Process = Process.Start("Notepad.exe", "text.txt")

    ' target --> The root AutomationElement.
    Dim target As AutomationElement = AutomationElement.FromHandle(p.MainWindowHandle)

    ' Specify the control type we're looking for, in this case 'Document'
    Dim cond As PropertyCondition = New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document)

    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 oAttribute As Object = textpatternPattern.DocumentRange.GetAttributeValue(TextPattern.FontWeightAttribute)
    If (oAttribute = TextPattern.MixedAttributeValue) Then
        Console.WriteLine("Mixed font weights.")
    Else
        Console.WriteLine(oAttribute.ToString())
    End If
End Sub

注解

此属性指的是字体的相对笔划、粗细或加粗。This attribute refers to the relative stroke, thickness, or boldness of a font.

此属性将建模 LOGFONT 中的 "lfWeight" 字段之后。This attribute is modeled after the lfWeight field in GDI LOGFONT. 为保持一致性,已采用 LOGFONT: 0 = Connectorrouting.dontcare,100 = 精简,200 = 超细或 UltraLight,300 = 浅色,400 = Normal 或 Regular,500 = 中等,600 = SemiBold 或 DemiBold,700 = Bold,800 = ExtraBold 或超粗,900 = 厚或黑色。For consistency, the following values have been adopted from LOGFONT: 0=DontCare, 100=Thin, 200=ExtraLight or UltraLight, 300=Light, 400=Normal or Regular, 500=Medium, 600=SemiBold or DemiBold, 700=Bold, 800=ExtraBold or UltraBold, and 900=Heavy or Black.

此标识符由 UI 自动化客户端应用程序使用。This identifier is used by UI Automation client applications. UI 自动化提供程序应在 TextPatternIdentifiers中使用等效字段。UI Automation providers should use the equivalent field in TextPatternIdentifiers.

UI 自动化客户端通过调用 GetAttributeValue获取属性的值。UI Automation clients get the value of the attribute by calling GetAttributeValue.

此属性的值的类型为 Int32Values for this attribute are of type Int32. 默认值为 zeroThe default value is zero.

适用于

另请参阅