如何使用其名称访问Winforms控件 [英] How to access a winforms control using its name
本文介绍了如何使用其名称访问Winforms控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在名为"txtName"的winforms窗体上创建了一个TextBox.现在,我想通过按名称来获取文本框控件的名称来显示该文本框的值,该名称存储在字符串变量中.
谢谢!
I have created a TextBox on a winforms form named "txtName". Now I want to show the value of the TextBox named "txtName" by fetching that TextBox control by its name, which is stored in a string variable.
Thank you!
推荐答案
很简单,要获取值,只需将带有存储名称的字符串发送到以下方法并获取其文本
Its quite simple, to get value simply send the string with stored name to following method and get its text
private string GetControlValue(string ControlName)
{
Control[] ctrls = this.Controls.Find(ControlName, true);
return ctrls[0].Text;
}
这篇关于如何使用其名称访问Winforms控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文