How can I create an Array of Controls in C#.NET?

后端 未结 4 2105
温柔的废话
温柔的废话 2021-01-03 15:48

I have a form which contains several standard controls (textbox\'s, buttons, etc). I want to group certain controls in collections so that I can enable and disable them at a

相关标签:
4条回答
  • 2021-01-03 16:02

    Have you considered using a layout manager? (as far as positioning goes) Keeping a list of controls (without specifying the control's position) will not automatically position the controls, a layout manager could help.

    0 讨论(0)
  • 2021-01-03 16:03

    If your not already using the tag property of the control then you could put some form of controlid in the tag and then enumerate the controls collection looking for the particular id you want and enable/disable them.

    0 讨论(0)
  • 2021-01-03 16:03

    Assuming you are using webforms and .net 3.5 you could have something like

    var cntrls = new List<WebControl>()
            {
                {new TextBox(){ID = "Textbox1"}},
                {new Button(){ID="Button1", Text = "Click me!"}}
            };
    
    cntrls.ForEach(x => x.Enabled = false);
    
    0 讨论(0)
  • 2021-01-03 16:11

    your example should be fine

    List<Control>
    

    will also work

    0 讨论(0)
提交回复
热议问题