在该方法中,若frmName窗体中包括名字为BtnTest的Button,就把该button的text设置为"Testing",请问该方法中的代码怎样写    
        public void SetButtonText(Form frmName)
        { 
          
        }谢谢

解决方案 »

  1.   

    frmName.Controls["BtnTest"].Text = "Testing";
      

  2.   

    1楼的假如不是普通的button,而是将frmName窗体中包括一个名字为statusStrip1的toolStripStatusLabel3的Text设置为LabelTest怎样写呢?
    (而statusStrip中有4个toolStripStatusLabel,名字分别为toolStripStatusLabel1、toolStripStatusLabel2、toolStripStatusLabel3、toolStripStatusLabel4)谢谢
      

  3.   

    Button but = (Button)frmName.FindControl("BtnTest");
    but.text="Testing"
      

  4.   

     toolStripLabel1.Text = "你好";
      

  5.   

    因为toolStripStatusLabel3是statusStrip1中子项的
      

  6.   

    遍历窗体控件啊,判断有就更改,没有就不改被
    foreach(Controls btn in frmName.Controls)
    {
        if(btn.Name == BtnTest)
           btn.Text=Testing;
    }不知道你说的是不是这个意思
      

  7.   

    是的,Btn是个简单的控件,可以那样写,
    但是statusStrip中个集合控件,其中可以多个toolStripStatusLabel、progressbar等,
    我现在要设置第三个toolStripStatusLabel的text,请问怎样写
      

  8.   

    /// <summary>
            /// 遍历control下的所有子孙控件
            /// 查询出所有控件名字(id)中含有keyName的数值
            /// </summary>
            /// <param name="control"></param>
            /// <param name="keyName"></param>
            /// <param name="foundControls"></param>
            /// <returns></returns>
            public static ArrayList FindControls(Control control, string keyName, ArrayList foundControls)
            {
                if (foundControls == null) foundControls = new ArrayList();
                foreach (Control subControl in control.Controls)
                {
                    if (subControl.HasControls())
                    {
                        foundControls = FindControls(subControl, keyName, foundControls);
                    }                if (subControl.ID == null) continue;                if (subControl.ID.IndexOf(keyName) != -1)
                    {
                        foundControls.Add(subControl);
                    }
                }            return foundControls;
            }
      

  9.   

    pls find it then convert the type