我接过别人的项目,他们用的是氪金工具包。当我更改 UI 上的任何内容(即添加按钮、编辑文本、添加菜单项)时,我收到此异常错误:
this.kryptonHeaderGroupMain.Controls.Add(this.kryptonHeaderGroupMain.Panel);
Cause an exception "ReadOnly controls collection"
..它弄乱了设计器 View 。
我错过了什么?
根据一些人的建议,我已经尝试过但仍然失败:
this.<kryptonControlsContainer>.Panel.Controls.Add(this.<otherControlName>);
最佳答案
Controls
KryptonHeaderGroup
的属性(property)control 是一个自定义控件集合(名为 KryptonReadOnlyControls
),它不允许添加或删除子控件。一路KryptonHeaderGroup
被设计的是它有一个Panel
它充当其子控件的容器。您需要做的如下。
在设计模式下:
在添加任何控件之前,确保选择面板而不是 KryptonHeaderGroup
本身。查看这些屏幕截图中的差异:
使用代码:
//kryptonHeaderGroup1.Controls.Add(new KryptonButton()); // Throws an exception.
kryptonHeaderGroup1.Panel.Controls.Add(new KryptonButton()); // Works fine.
注意:同样的逻辑适用于其他控件,如 KryptonGroupBox
, KryptonGroup
, 和 KryptonSplitContainer
.
关于c# - 导致异常 "ReadOnly controls collection"- 编辑 UI 时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58493395/