通过 AutomationElement 设置 DateTimePicker 元素
我希望能够通过 AutomationElement
将 DateTimePicker
元素设置为特定时间。它将时间存储为“hh:mm:ss tt”(即 10:45:56 PM)。
我得到这样的元素:
ValuePattern p = AECollection[index].GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
我相信我有两个选择:
p.SetValue("9:41: 22 AM");
或
p.Current.Value = "9:41:22 AM";
但是,第一个选项根本不起作用(我在某处读到这可能在 .NET 2.0 中被破坏?,但我正在使用 .NET 3.0)。第二个选项告诉我该元素是只读的,如何更改状态以使其不是只读的?或者更简单地说,我如何更改时间:(?
I want to be able to set a DateTimePicker
element to a certain time via AutomationElement
. It stores the time as "hh:mm:ss tt" (i.e. 10:45:56 PM).
I get the element as such:
ValuePattern p = AECollection[index].GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
I believe I have two options:
p.SetValue("9:41:22 AM");
or
p.Current.Value = "9:41:22 AM";
However, the first option simply doesn't work (I read somewhere that this may be broken in .NET 2.0?, I am using .NET 3.0 though). The second option tells me that the element is read only, how can I change the status so that it is not read only? Or more simply, how can I change the time :( ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以获取本机窗口句柄并发送
DTM_SETSYSTEMTIME
消息来设置DateTimePicker
控件的选定日期。为此,我想您已经找到了该元素,然后您可以使用以下代码:
DateTimePickerHelper
这是
DateTimePickerHelper
的源代码。该类有一个公共静态SetDate
方法,允许您为日期时间选择器控件设置日期:You can get the native window handle and send
DTM_SETSYSTEMTIME
message to set the selected date forDateTimePicker
control.To do so, I suppose you have found the element, then you can use follwing code:
DateTimePickerHelper
Here is the source code for
DateTimePickerHelper
. The class has a public staticSetDate
method which allow you to set a date for the date time picker control:该解决方案适用于基于 Wpf 的应用程序
This solution works for Wpf based app
我来到这里是因为我遇到了同样的问题。
我尝试通过以下方式设置 DateTimePicker 日期:
您必须聚焦应用程序窗口,然后是 DateTimePicker,然后输入使用 SendKeys.SendWait 方法的日期。
来源:
这是使用 FlaUI 包的示例代码:
我知道该示例代码可以简化,但这就是它在我的机器上的工作方式。
因此,我将其原样发布在这里。我希望这有帮助。
I came here because I had the same problem.
I've tried setting the DateTimePicker Date via:
You have to focus the application window, then the DateTimePicker and then enter the date using the SendKeys.SendWait method.
Sources:
Here's an example code that uses the FlaUI package:
I am aware that the example code can be simplified, but this is how it worked on my machine.
Therefore, I posted it here as it is. I hope this helps.