c# - 无法在 Winforms 控件中找到新的子类属性

标签 c# winforms textbox

感谢这里的帮助,我已经设法递归循环我的 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/

相关文章:

c# - 检测鼠标点击控件数组

c# - 如何处理 GridColums 和 Rows?

c# - 正在运行任务的关闭表单

wpf - 如何通过带有文本框的 ListView 作为 TreeViewItems 进行 TAB?

JavaScript Unicode 输入文本框

c# - 在同一个循环中进行两次线性插值,但其中一次需要更长的时间,为什么? (统一3D)

.NET RichTextBox 制表符

c# - 当应用程序通过 Windows API 全屏显示时,菜单不合适

c# - 在文本框中插入制表符

c# - 有没有 BDD 的成功案例?