0

当我想开始一些工作时,我不知道我的方式是对还是错,我将禁用所有控制并在工作完成后再次启用。这是我的代码:

public void EnableControls(bool isenable){
this.BeginInvoke(new MethodInvoker(delegate()
{   
    foreach (System.Windows.Forms.Control control in this.Controls)
    {
        control.Enabled = isenable;
    }
}));}

with : 这是表单控件

每个人都可以向我解释这段代码是错还是对。当我使用许多线程时,我看到控件无法启用,我不知道为什么。谢谢 !

4

1 回答 1

0

If you want to enable/disable all controls in the form, you can just use form.Enabled instead. If however there are some controls that you don't want to take a part in enable/disable you can put all controls that are interested in Panel or GroupBox and Enable/Disable panel. And at least if you can't use Panel, your code is fine in this case

于 2012-11-30T10:52:57.143 回答