感谢这里的帮助,我已经设法递归循环我的 winform 上的所有控件并找到我的子类控件但是当我尝试更新我的用户定义属性 _key 和 _value 时,对象 ctrl 不会公开它们:( 我在用着 下面的 ctrlContainer 是这样传递的调用表单
foreach (Control ctrl in ctrlContainer.Controls)
{
// code to find my specific sub classed textBox
// found my control
// now update my new property _key
ctrl._key does not exist :(
I know the ctrl exists and is valid because ctrl.Text = "I've just added this text" works.
_key is visible when looking at the control in the form designer.
}
任何人都可以提示我做错了什么吗? 谢谢。
最佳答案
_key
不存在,因为您正在查看 Control
。
尝试做:
foreach (var ctrl in ctrlContainer.Controls.OfType<MyControl>())
{
ctrl._key = "somthing";
}
关于c# - 无法在 Winforms 控件中找到新的子类属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8533308/