我定义了一个委托 是这样写的
        
public delegate void ButtonChange(Button bt, string str, bool a);
        
public void Change(Button bt, string str, bool a)
{
bt.Text = str;
bt.Enabled = a;
}public void ShowChange(Button bt, string str, bool a)
{
ButtonChange my = new ButtonChange(Change);
object[] obj = new object[] { str, a };
bt.Invoke(my, obj);
}传一个按钮控件进去,但是我在调用的时候,报“参数计数不匹配”的异常
由于窗体中有大量控件,如果一个控件写一个委托的话,很麻烦,有什么方法可以实现,谢谢大家。

解决方案 »

  1.   

    change接收三个参数,你传进去两个参数.应该是不匹配的吧?
      

  2.   

    调用的时候 我也传3个参数进去的呀
    frmClienUp.ShowChange( FrmClientUp.frm.button1, "停止生成", true);
      

  3.   

    ButtonChange my = new ButtonChange(Change); 
      

  4.   

    ButtonChange my = new ButtonChange(Change);你定义的委托传的是3个参数
      

  5.   

    写成类或者是结构吧
    eventargs
      

  6.   

    public void ShowChange(Button bt, string str, bool a) 

    ButtonChange my = new ButtonChange(Change); 
    object[] obj = new object[] { str, a }; 
    bt.Invoke(my, obj); ------这里改   bt.Invoke(bt,my, obj); 

      

  7.   


    public delegate void ButtonChange(Button bt, string str, bool a);
           
    public void Change(Button bt, string str, bool a)
    {
    bt.Text = str;
    bt.Enabled = a;
    }public void ShowChange(Button bt, string str, bool a)
    {
    ButtonChange my = new ButtonChange(Change);
    object[] obj = new object[] {bt, str, a };//此处应该传递三个参数给委托调用指向的过程。
    bt.Invoke(my, obj);

      

  8.   


    public delegate void ButtonChange(object[] obj); 
            
    public void Change(object[] obj) 

    bt.Text = obj[0].Tostring(); 
    bt.Enabled =(bool)obj[1]; 
    } public void ShowChange(Button bt, string str, bool a) 

    ButtonChange my = new ButtonChange(Change); 
    object[] obj = new object[] { str, a }; 
    this.Invoke(my, obj); 
      

  9.   

    public delegate void ButtonChange(object sender, ShowEventArgs e); 
            
    public void Change(object sender, ShowEventArgs e) 

    ((button)sender).Text=e.str;
    ((button)sender).Enabled = e.a; 
    } public void ShowChange(Button bt, string str, bool a) 

    ButtonChange my = new ButtonChange(Change); 
    ShowEventArgs ea=new ShowEventArgs();
    ea.str=str;
    ea.a=a;
    bt.Invoke(my, ea); 
    }
    public ShowEventArgs:EventArgs
    {
    public str="";
    public bool a=false;
    }
    这样不知道对不