c# - 如何在 FlowLayoutPanel 中查找标签
问题描述
我有 ac#FlowLayoutPanel
容器,我在其中添加了许多Label.Text
设置为不同值的标签,即Label.Text = "ABCDEF"
.
搜索容器中的所有标签以找到带有 的特定标签的最佳方法是Text = "ABCDEF"
什么?
谢谢你
解决方案
You can find the label with text as follow:
foreach (var item in flowLayoutPanel1.Controls)
{
if (item is Label)
{
if ("ASDF" == ((Label)item).Text)
{
MessageBox.Show("found it");
}
}
}
Also if you know your component's name, you can search it as below:
foreach (var item in flowLayoutPanel1.Controls.Find("label1", true))
{
if ("ASDF" == ((Label) item).Text)
{
MessageBox.Show("found it");
}
}
推荐阅读
- graphviz - 点中两条记录的排名相同
- python - 与python中子进程打开的`/dev/tty`交互
- c - 如何在 C 中为自定义 Wireshark 解剖器创建新名称?
- json - 通过 Power Automate 创建专用通道 JSON 和/或图形 API 有什么问题?
- python - MySQL 执行语句返回 NoneType
- javascript - 无法使用 vuejs 和 electronjs 创建简单的文件资源管理器
- python - IndexError:索引 2 超出轴 2 的范围,大小为 2
- vue.js - 从其他组件调用方法
- angular - 如何根据显示值过滤 agGrid 中的行?
- perforce - 我们如何在 perforce 中签出文件的特定版本?