如何同时调用多个按钮
我在同时调用多个按钮时遇到问题,因为每个按钮的工作进程不同,有超过 78 个文件夹。
我想在一个名为“button4”的按钮中同时调用所有按钮。现在它仅调用button1,而不适用于button2。
有什么办法可以同时调用这些按钮吗?
我的代码是:
private void button4_Click_1(object sender, EventArgs e)
{
button1.PerformClick();
button2.PerformClick();
}
提前致谢。
I am having a problem in calling multiple buttons at the same time because each buttons works a different process there are more than 78 folders.
I want to call all the buttons at the same time in a single button called button4. Now it's calling button1 only and not working for button2.
Is there any way to call these buttons at the same time?
My code is:
private void button4_Click_1(object sender, EventArgs e)
{
button1.PerformClick();
button2.PerformClick();
}
Thanks in Advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
通常,您不应该通过对其他按钮执行 UI 样式的单击来调用它们的行为。
只需调用您想要“单击”的按钮的相应事件处理方法即可。
示例代码:
You should in general not perform UI-style clicks on other buttons in order to invoke their behaviour.
Just call the respective event handling methods of the buttons you would like to "click".
example code:
您应该重构其他事件以调用命名良好的方法。
假设button1做了一些初始化;它应该看起来像这样:
假设按钮2完成了初始化;它应该看起来像这样:
然后如果button4 完成所有这些;它应该看起来像这样:
You should refactor the other events to call well-named methods.
Say button1 does some initialization; it should look like this:
Say button2 finalizes that intialization; it should look like this:
Then if button4 does all of this; it should look like this:
在大多数情况下,您根本不应该调用
PerformClick()
。相反,您应该调用事件处理程序调用的相同方法。因此,如果单击按钮 3 的行为应与单击按钮 1 然后单击按钮 2 的行为相同,则您应该具有如下代码:(作为旁注,您的按钮应具有描述性名称,而不是
button1
等.)Under most circumstances, you shouldn't call
PerformClick()
at all. Instead, you should call the same methods your event handlers call. So, if clicking button 3 should behave as click clicking button 1 and then button 2, you should have code like this:(As a side note, your buttons should have descriptive names, not
button1
and the like.)我们无法说出这些按钮单击处理程序的作用。所以很难说哪里出了问题。但尝试将代码从按钮单击处理程序移开。创建一些包含单击按钮后应运行的代码的类。然后从按钮单击处理程序调用此类的方法。调试和测试该代码会更容易。
We can't say what those button click handlers do. So it's hard to say what's wrong. But try moving the code away from button click handlers. Create some class that contains code that should run after button click. Then call this class' methods from button click handlers. It will be easier to debug and test that code.