How to get element's text by TabIndex in Windows Forms? smth like:
"this.Controls.GetElementByTabindex(1).text"
Is it possible?
Yes, it is possible with LINQ
:
var text = this.Controls.OfType<Control>()
.Where(c => c.TabIndex == index)
.Select(c => c.Text)
.First();
If you want to do it with extension method:
public static class MyExtensions
{
public static string GetElementTextByTabIndex(this Control.ControlCollection controls,int index)
{
return controls.OfType<Control>()
.Where(c => c.TabIndex == index)
.Select(c => c.Text).First();
}
}
string text = this.Controls.GetElementTextByTabIndex(1);
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