导致异常 "ReadOnly controls collection" - 编辑时 UI

Cause an exception "ReadOnly controls collection" - when editing UI

接过别人的项目,他们用的是氪金工具包。当我更改 UI 上的任何内容(即添加按钮、编辑文本、添加菜单项)时,我收到此异常错误:

this.kryptonHeaderGroupMain.Controls.Add(this.kryptonHeaderGroupMain.Panel);

Cause an exception "ReadOnly controls collection"

..它弄乱了设计器视图。

我错过了什么?

有人推荐的,我试过了还是失败了:

this.<kryptonControlsContainer>.Panel.Controls.Add(this.<otherControlName>);

KryptonHeaderGroup 控件的 Controls 属性 是一个自定义控件集合(名为 KryptonReadOnlyControls),它不允许添加或删除子控件。 KryptonHeaderGroup 的设计方式是它有一个 Panel 作为其子控件的容器。您需要做的如下。

在设计模式中:

在添加任何控件之前,请确保您 select 面板而不是 KryptonHeaderGroup 本身。查看这些屏幕截图的不同之处:

使用代码:

//kryptonHeaderGroup1.Controls.Add(new KryptonButton());        // Throws an exception.
kryptonHeaderGroup1.Panel.Controls.Add(new KryptonButton());    // Works fine.

注意: 相同的逻辑适用于其他控件,如 KryptonGroupBoxKryptonGroupKryptonSplitContainer