gpt4 book ai didi

c# - 在 C# winform 中通过 TabIndex 获取元素的文本

转载 作者:行者123 更新时间:2023-11-30 14:11:06 37 4
gpt4 key购买 nike

如何在Windows 窗体中通过TabIndex 获取元素的文本?像:

"this.Controls.GetElementByTabindex(1).text"

这可能吗?

最佳答案

是的,可以使用 LINQ:

var text = this.Controls.OfType<Control>()
.Where(c => c.TabIndex == index)
.Select(c => c.Text)
.First();

如果你想用扩展方法来做:

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);

关于c# - 在 C# winform 中通过 TabIndex 获取元素的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21300277/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com