频道栏目
首页 > 资讯 > C# > 正文

C# 在winform中查找控件

10-08-11        来源:[db:作者]  
收藏   我要投稿

/// <summary>
/// 在winform中查找控件
/// </summary>

/// <param ></param>
/// <param ></param>
/// <returns></returns>
private System.Windows.Forms.Control findControl(System.Windows.Forms.Control control, string controlName)
{
    Control c1;
   
foreach (Control c in
control.Controls)
    {
       
if (c.Name ==
controlName)
        {
           
return
c;
        }
       
else if (c.Controls.Count > 0
)
        {
            c1
=
findControl(c, controlName);
           
if (c1 != null
)
            {
               
return
c1;
            }
        }
    }
   
return null
;
}

//调用


for (int i = 1; i <= 30; i++)
{
   
string _box = "b" +
i.ToString();
    TextBox tb
= (TextBox)this
.findControl(groupBox2, _box);
    tb.Text
=
i.ToString();
}

    
相关TAG标签
上一篇:C#两种任意类型转换支持(示例:String convert to Type)
下一篇:菜鸟谈谈C#中的构造函数和析构函数
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站