How to enable ALL controls on a form?

前端 未结 5 580
清歌不尽
清歌不尽 2021-01-03 00:08

Currently I have most of my form\'s controls disabled at launch because you cannot use them until a file is loaded. However, once the file is loaded the controls should beco

5条回答
  •  温柔的废话
    2021-01-03 00:22

    Recursion

    private void enableControls(Control.ControlCollection Controls)
    {
        foreach (Control c in Controls)
        {
            c.Enabled = true;
            if (c is MenuStrip)
            {
               foreach(var item in ((MenuStrip)c).Items)
               { 
                  item.Enabled = true;
               }
            }
            if (c.ControlCollection.Count > 0)
                enableControls(c.Controls);
    
        }
    }
    

    Edit

    Should have been checking the control Collection count instead of HasControls Which is Webcontrols

提交回复
热议问题