2009-06-17 32 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