【发布时间】:2011-06-19 18:52:53
【问题描述】:
我有按钮网格。我想在没有任何按键或鼠标事件的情况下单击一个按钮(调用单击事件)。只希望在有限的时间间隔(3 秒)内自动单击它。
【问题讨论】:
标签: c# wpf events button wpf-controls
我有按钮网格。我想在没有任何按键或鼠标事件的情况下单击一个按钮(调用单击事件)。只希望在有限的时间间隔(3 秒)内自动单击它。
【问题讨论】:
标签: c# wpf events button wpf-controls
您可以使用 WPF 中的自动化界面以编程方式单击按钮。当然,如果您使用命令而不是处理点击事件(强烈推荐),那么您可以调用命令。
这是使用来自Josh Smith's blog 的自动化单击按钮的代码。
var peer = new ButtonAutomationPeer(someButton);
var invokeProv = peer.GetPattern(PatternInterface.Invoke) as IInvokeProvider;
invokeProv.Invoke();
【讨论】:
您可以使用 Timer 并在 Elapsed 事件中调用您喜欢的任何内容?
// Create a timer with a three second interval.
myTimer = new System.Timers.Timer(3000);
myTimer.Elapsed += new ElapsedEventHandler(YourEventHere);
myTimer.Enabled = true;
【讨论】: