C# WinForms FlowLayoutPanel 锁定子控件

C# WinForms FlowLayoutPanel locking child controls

我有一个包含如下元素的基本表单:
- pnlSearch Panel 类型:搜索按钮
- 类型 FlowLayoutPanel 的 pnlActions:添加、编辑、删除、导出等按钮

没有任何内容被锁定,两个面板的修饰符都是 Private & 按钮的修饰符是 Protected

FlowLayoutPanel 用于自定义子表单中的选项(例如删除删除选项)而不留空格,因为元素将相应地流动。

在子表单中,只能访问搜索按钮。 pnlActions 中的按钮在设计器中被锁定,但通过检查属性 Locked = FalseModifiers= Protected

尝试将 pnlActions 的修饰符设置为 Protected,但它仍然是一样的。

知道是什么导致了这种行为吗?
除了内部控件布局外,PanelFlowLayoutPanel 之间有什么区别?
如果我手动编写任何代码,我会 post 编写示例代码,但它们都是由设计师生成的

我在 Win7 上使用 VS 2013 如果这很重要
提前致谢

这是设计师的问题。如果您通过代码进行更改,则一切正常... 问题不会得到解决,因为该平台不再由微软维护。

我知道这是一个老问题,但我分享了一个可能的解决方案,以备不时之需。

我们将创建一个继承FlowLayoutPanel的class,我将其命名为FlowLayoutPanelHeritable。您可以将它放在您认为合适的命名空间中,对于此示例,命名空间为 WindowsFormsApp.

using System.ComponentModel;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace WindowsFormsApp
{
    [Designer(typeof(ParentControlDesigner))]
    public class FlowLayoutPanelHeritable : FlowLayoutPanel
    {
    }
}

首先我们必须在FatherFormProtected中设置FlowLayoutPanel的修饰符。现在我们必须通过FatherForm中的代码进行修改,访问FatherForm.designer.cs。我们将用 FlowLayoutPanelHeritable 替换 FlowLayoutPanel 的每个实例(在变量的创建和初始化中)。然后我们保存,重新编译。

现在如果你访问ChildForm,你会发现你不再有设计时的修改限制。

重要提示:如果你想编辑FatherForm,你必须访问FatherForm.designer.cs并再次将所有FlowLayoutPanelHeritable替换为FlowLayoutPanel;完成编辑后,执行相反的过程。