c# 窗体下有的子窗体,里面有很多动态控件,为什么遍历的时候只能找出一个来?
1、步骤1,有个功能是新建窗体,富文本停靠在窗体上,代码如下
Form fm = new Form();
fm.Location = new Point(0, 0);
fm.TopMost = true;
fm.MdiParent = this;
fm.AutoScroll = true;
fm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
RichTextBox rt = new RichTextBox();
rt.Dock = System.Windows.Forms.DockStyle.Fill;
rt.Location = new Point(0, 0);
rt.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.None;
rt.ReadOnly = true;
rt.BackColor = System.Drawing.Color.White;
fm.Controls.Add(rt);
fm.Show();
2、在新建的窗体,里面动态添加文本框,代码如下:
int name = new DateTime().Millisecond;
TextBox txtBox = new TextBox();
txtBox.Name = "txt" + name;
txtBox.Multiline = true;
txtBox.Size = new System.Drawing.Size(100, 25);
txtBox.BorderStyle = BorderStyle.FixedSingle;
txtBox.Location = new Point(25 + count, 20 + count);
Form activeForm=this.ActiveMdiChild;//获取被激活的窗体
foreach(Control crl in activeForm.Controls)
{
if(crl is RichTextBox)