2009-06-17 37 views
1

我有一个WinForms应用程序,我似乎无法通过UIAutomation访问ToolStripStatusLabel的文本。微软implies支持StatusStrip s(以及其中的项目)是有限的,但这似乎是一个基本的足够用例,它应该工作。UIAutomation与ToolStripStatusLabel

该控件在UISpy中显示为ControlType.Edit,似乎只是只读文本框,但其值始终与其名称相同,而不是其文本。是

在UISpy的属性如下:

AutomationElement 
    General Accessibility 
    AccessKey: "" 
    AcceleratorKey: "" 
    IsKeyboardFocusable: "False" 
    LabeledBy: "(null)" 
    HelpText: "" 

    State 
    IsEnabled: "True" 
    HasKeyboardFocus: "False" 

    Identification 
    ClassName: "" 
    ControlType: "ControlType.Edit" 
    Culture: "(null)" 
    AutomationId: "StatusBar.Pane0" 
    LocalizedControlType: "edit" 
    Name: "My Label" 
    ProcessId: "3972 (*****)" 
    RuntimeId: "42 134002 0" 
    IsPassword: "False" 
    IsControlElement: "True" 
    IsContentElement: "True" 

    Visibility 
    BoundingRectangle: "(9, 273, 79, 17)" 
    ClickablePoint: "48,281" 
    IsOffscreen: "False" 

ControlPatterns 
    GridItem 
    Row: "0" 
    Column: "0" 
    RowSpan: "1" 
    ColumnSpan: "1" 
    ContainingGrid: ""status bar" "statusStrip"" 

    Value 
    Value: "My Label" 
    IsReadOnly: "True" 

基本上,我希望一段路要走myLabel.Text = "something"并能够通过UIAutomation获得该值出莫名其妙。

回答

1

设置AccessibleName财产除.Text控制ToolStripStatusLabel。它的工作原理我在一个类似的方案采用白色为:

statusLabel.Text = statusLabel.AccessibleName = "New status value";

0

我不得不通过使用两个不同文本的不同标签来显示和隐藏相应的标签来解决此问题。这对我来说已经足够了(用White测试),但我很惊讶UIAutomation没有显示文本值 - 它基本上意味着WinForms应用程序中的状态栏中的所有文本都无法被屏幕阅读器访问。

0

我从来没有遇到过检索类似于您所描述的标签文本的问题。实际上,AutomationId在我的应用程序中甚至是相同的。 ControlType显示为ControlType.Edit这一事实具有误导性。例如下面的工作

statusText = (string)automationElement.GetCurrentPropertyValue(ValuePattern.ValueProperty); 

automationElement已经使用针对ControlType.Edit一个查找方法与"StatusBar.Pane0"AutomationId定位。

+0

啊,有意思。我会在下周尝试这个!任何想法为什么它可能会被暴露为编辑控制?这对我来说很好,但它似乎会误导屏幕阅读器。 – Thom 2009-08-29 11:29:09