How to get all controls in form with C#

1 Answer

0 votes
namespace WinFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            label1.Text = "";
            foreach (Control c in Controls)
            {
                label1.Text += c.Name + Environment.NewLine;
            }
        }
    }
}



/*
 * run:
 *
 * listBox1
 * richTextBox1
 * textBox1
 * label1
 * button1
 * 
 */

 



answered Aug 19, 2023 by avibootz

Related questions

1 answer 135 views
1 answer 110 views
110 views asked Sep 5, 2023 by avibootz
1 answer 177 views
1 answer 128 views
1 answer 142 views
1 answer 117 views
1 answer 96 views
...