首页 > 解决方案 > 在 C# 中循环所有创建的按钮

问题描述

        private void flowLayoutPanel1_Click(object sender, MouseEventArgs e)
        {
            int x = e.X;
            int y = e.Y;
            newBtn = new Button(); //I created private var
            newBtn.Size = new System.Drawing.Size(78, 76);
            newBtn.BackColor = System.Drawing.Color.White;
            newBtn.Location = new System.Drawing.Point(x+62,y+80);
            newBtn.Text = "Created button";
            this.Controls.Add(newBtn);
            newBtn.BringToFront();
        }

假设创建了 10 个按钮,我怎样才能为所有按钮循环?
喜欢:

foreach(Button btn in this.Controls.list(newBtn)){
}

标签: c#winforms

解决方案


推荐阅读