I am working in C# on an existing WinForm project. The original code uses Tag to convey hardware addressing info for a bunch of textboxes that represent certain hardware registers in a connected microcontroller system. I know how to find an unknown control by searching for its Name using the Control.ControlCollection.Find method, but it's unclear to me on whether I can find the control by the Tag (just a string in this instance).
You can use LINQ
to find controls based on Tag
var items = parentControl.ControlCollection;
var item = items.Cast<Control>().FirstOrDefault(control => String.Equals(control.Tag, tagName));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With