1

我正在尝试将水平滚动条的值从 -1 更改为 -2。我可以访问它..但接下来我必须更改它的值..

AutomationElement _sideBar = _ClickButtonElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ClassNameProperty, "WindowsForms10.SCROLLBAR.app.0.378734a"));

_clickButtonElement 是滚动条父窗口的 AutomationElement。

4

2 回答 2

1

滚动条通常支持RangeValuePattern。使用类似的东西:

RangeValuePattern range = scrollbar.GetCurrentPattern(RangeValuePattern.Pattern) as RangeValuePattern;
range.SetValue(50); // Set to half way point

请注意,无论内部值如何,通常滚动条都被标准化为 0..100。因此,如果滚动条内部使用值 -5 到 5,则滚动条的中间点 0 实际上将通过 RangeValuePattern 暴露为 50。

您可能希望使用Inspect 工具来确保您获得了正确的元素,并且它也支持这种模式。在编写任何代码之前,您还可以使用 Inspect 通过其 UI 调用 RangeValue.SetValue()。

于 2012-06-13T09:08:53.367 回答
0
AutomationElement aeForm = AutomationElement.FromHandle(windowPtr);

AutomationElementCollection buttonCollection = aeForm.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ScrollBar));          

AutomationElement aeButton = buttonCollection[1];

RangeValuePattern rcpattern = (RangeValuePattern)aeButton.GetCurrentPattern(RangeValuePattern.Pattern);
rcpattern.SetValue(50.00);
于 2012-06-14T06:22:02.833 回答