解决方案 »

  1.   

    你可以将新建的组件放到一个List中,你遍历就行了,或者给它们起一个有规律的name,然后通过Controls[名字] 找到
      

  2.   

    this.flowLayoutPanel1.Refresh();
    赋值完执行一下这个试试
      

  3.   

     con.text =0;修改为 con.Text="0";
      

  4.   

    加上 else { MessageBox.Show("没有找到文本框!"); }之后,运行提示“没有找到文本框”,不知为何。
      

  5.   

    除了这句要纠正外con.text =0;改为con.Text = "0";
    虽然没你那个控件,用普通TextBox测试代码没问题.
      

  6.   

    哦,难道是我的控件有问题么?
    我的控件代码:using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Data;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;namespace Login
    {
        public partial class myControl : UserControl
        {
            public myControl()
            {
                InitializeComponent();
            }
            public TextBox myTextbox{ 
    get { 
    return textBox1; 

    set { 
    textBox1 = value; 


    public Label myLabel{
        get
        {
            return label1;
        }
        set
        {
            label1 = value;
        }
    }
            private void myControl_Load(object sender, EventArgs e)
            {
                
            }
        }
    }
      

  7.   


        public partial class Form1 : HSEI.Windows.Forms.RobbinForm
        {
            private List<TextBox> tbList = new List<TextBox>();        public Form1()
            {
                InitializeComponent();
                Init();
            }        private void Init()
            {
                for(int i=0;i<10;i++)
                {
                    TextBox tb = new TextBox();
                    tb.Text = "";
                    tbList.Add(tb);
                    //TODO Layot Add Control
                }
            }        private void Reset()
            {
                foreach(var tb in tbList)
                {
                    tb.Text = "0";
                }
            }
        }
    你的程序中把TextBox换成自定义控件就行了
      

  8.   

    你用自定义控件肯定是有问题的。foreach在panel里面遍历到的是你的myControl,他根本就没有Text属性,你要改的是myControl里面的TextBox的Text的属性。改一下Clear按钮下的代码。            UserControl.ControlCollection cc = this.flowLayoutPanel1.Controls;
                foreach (UserControl con in cc)
                {
                    if (con is UserControl)
                    {
                        con.Controls[0].Text = "0";
                    }
                    // else { MessageBox.Show("没有找到文本框!"); }
                }