Finding a control on a Winforms using LINQ?

后端 未结 4 2017
灰色年华
灰色年华 2020-12-09 13:14

I am trying to find an elegant way to get controls on a Windows Forms form by name. For example:

MyForm.GetControl \"MyTextBox\"

...

But t

4条回答
  •  我在风中等你
    2020-12-09 13:31

    Not so easy...

    LINQ isn't very good at recursion and Control.Controls isn't LINQ enabled (needs Cast).

    Sometimes a method is the best solution. Since you can write one that works for all Controls it will be even more reusable than a LINQ query. It could be an extension method.

提交回复
热议问题