foreach Windows应用程序中的按钮单击事件

foreach Windows应用程序中的按钮单击事件

问题描述:

如何在foreach中设置按钮单击事件?示例(我在Windows应用程序中使用多个文件上载,所以我使用了单按钮单击眉并设置了第一个标签,然后再次单击了相同的按钮眉文件来设置了第二个标签),所以我只问

how to set the button click event within foreach? Example( i am using multiple file upload in windows application, so i used single buttion click brows and set 1st lable ,and again i click same button brows file to set 2nd lable) so only i ask

您应该在循环的每次迭代中调用Application.DoEvents().在按钮上单击将变量设置为True,然后循环检查该变量.如果是真的,请中断,否则继续.

这不是一个很好的解决方案. Application.DoEvents()可能非常危险.最好的选择是有一个后台线程.
You should call Application.DoEvents() in every iteration your loop. On Button-Click set a variable to True and in loop check that variable. If it is true, break otherwise continue.

This is not a very good solution. Application.DoEvents() can be very dangerous. The best option here to do is to have a background thread.