在 C# 中按名称获取 Windows 窗体控件 [英] Get a Windows Forms control by name in C#

查看:35
本文介绍了在 C# 中按名称获取 Windows 窗体控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 myMenuToolStripMenuItem.我怎样才能像这样访问它:

I have a ToolStripMenuItem called myMenu. How can I access this like so:

/* Normally, I would do: */
this.myMenu... etc.

/* But how do I access it like this: */
String name = myMenu;
this.name...

这是因为我从 XML 文件动态生成 ToolStripMenuItems,并且需要通过其动态生成的名称引用 MenuItems.

This is because I am dynamically generating ToolStripMenuItems from an XML file and need to reference MenuItems by their dynamically generated names.

推荐答案

使用 Control.ControlCollection.Find 方法.

试试这个:

this.Controls.Find()

这篇关于在 C# 中按名称获取 Windows 窗体控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆