标题:初学C#,求助容器内查找控件的问题
只看楼主
肉_夹馍
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2013-5-2
结帖率:0
已结贴  问题点数:20 回复次数:2 
初学C#,求助容器内查找控件的问题
现form下有一tabControl,含有四个TabPages,每个page有含有一个tablelayoutpanel,每个panel含有100个lable,共400个,现在我想用类似controls的方法去遍历这些个lable,该怎么操作呢??

pannel内查找label可以,
((Label)tableLayoutPanel2.Controls["label" + i.ToString()]).Text

tabpages内查找该怎么操作呢?
搜索更多相关主题的帖子: controls 
2013-05-02 09:28
yhlvht
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:36
帖 子:707
专家分:4405
注 册:2011-9-30
得分:10 
foreach (TabPage page in tabControl1.TabPages)
            {
                foreach (Control c in page.Controls)
                {
                    TableLayoutPanel tPanel = c as TableLayoutPanel;
                    if (tPanel != null)
                    {
                        foreach (Control ctl in tPanel.Controls)
                        {
                            Label lab = ctl as Label;
                            if (lab != null)
                            {
                                //lab.Text
                            }
                        }
                    }
                }
            }
2013-05-02 12:52



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-406053-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.357152 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved