Loop through all controls of a Form, even those in GroupBoxes

后端 未结 9 1121
囚心锁ツ
囚心锁ツ 2020-11-29 05:17

I\'d like to add an event to all TextBoxes on my Form:

foreach (Control C in this.Controls)
{
    if (C.GetType() == typeof(System.Windows.Forms         


        
9条回答
  •  粉色の甜心
    2020-11-29 06:08

    Updated answer:

    I needed to disable all the controls in a form, including groupboxes. This code worked:

        private void AlterControlsEnable(bool ControlEnabled)
        {
            foreach (Control i in Controls)
                i.Enabled = ControlEnabled;
        }
    

提交回复
热议问题