代码之家  ›  专栏  ›  技术社区  ›  Thom

带ToolStripStatusLabel的ui自动化

  •  1
  • Thom  · 技术社区  · 16 年前

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

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

    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以某种方式获得这个价值。

    3 回复  |  直到 16 年前
        1
  •  1
  •   Sounten    12 年前

    设置 AccessibleName .Text ToolStripStatusLabel 控制。在类似的情况下,我也可以使用白色:

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

        2
  •  0
  •   Thom    16 年前

    为了解决这个问题,我必须使用两个不同文本的单独标签,并显示和隐藏相应的标签。就我的目的而言,这已经足够了(用白色测试),但我很惊讶uiautomation没有显示文本值——这基本上意味着WinForms应用程序状态栏中的所有文本对屏幕阅读器都是不可访问的。

        3
  •  0
  •   Sam Warwick    15 年前

    检索类似于您描述的标签文本时,我从来没有遇到过问题。事实上 AutomationId 在我的应用程序中也是一样的。事实是 ControlType 如图所示 ControlType.Edit 是误导。例如,以下内容将起作用

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

    在哪里? automationElement 已使用查找方法查找 控件类型.编辑 用一个 自动识别 属于 "StatusBar.Pane0" .