简体   繁体   English

Visual C# 如何模拟单击按钮?

[英]Visual C# How do you simulate click a button?

Is there any way to run a button's event handler from code?有没有办法从代码运行按钮的事件处理程序?

I tried我试过

btn.click(); btn.mousedown();

I tried calling the event handler but I didn't know what parameter goes to RoutedEventArgs e我尝试调用事件处理程序,但我不知道RoutedEventArgs e参数是什么

you can directly call the button using btn.click();您可以使用btn.click();直接调用按钮btn.click(); and btn.mousedown();btn.mousedown(); and pass a new EventArgs( ) RoutedEventArgs.并传递一个new EventArgs( ) RoutedEventArgs。

Like喜欢

btn.click(btn,new EventArgs());

You can also call你也可以打电话

btn.PerformClick();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM