如何防止容器控件在设计时转移到用户控件中?

发布于 2024-09-30 04:20:01 字数 176 浏览 7 评论 0原文

我有一个自定义控件,其中包含 6 个面板控件,这些控件的作用类似于设计时放入的其他控件的容器。这是通过创建继承 ParentControlDesign 的自定义设计器来完成的。在设计器中,我使用 EnableDesignMode 启用每个面板控件的设计时功能。问题是,当我使用该控件时,我可以移动面板。在设计时我可以做什么来防止它们移动?

I have a custom control that contains 6 panel controls that act like containers for other controls that are dropped in during design time. This was done by creating a custom designer inheriting from ParentControlDesign. In the designer, I use EnableDesignMode to enable design time functionality for each panel control. The problem is that when I use the control, I can move the panels around. What can I do to prevent them from moving while in design time?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

巾帼英雄 2024-10-07 04:20:01

我找不到解决这个问题的理想解决方案,只是部分解决方案。我假设您按照 这个答案

改变面板的设计行为需要给它们自己的设计师。下面是执行此操作的示例类:

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

[Designer(typeof(MyPanelDesigner))]
public class MyPanel : Panel {
    private class MyPanelDesigner : ScrollableControlDesigner {
        public override SelectionRules SelectionRules {
            get { return SelectionRules.None; }
        }
    }
}

将 UC 中的面板替换为 MyPanel。自定义的 SelectionRules 属性可确保用户无法轻松地使用鼠标将面板拖动到另一个位置。不过,“位置”和“大小”属性仍然可以在属性网格中进行编辑。为了摆脱这个问题,我认为你需要重写 PreFilterProperties()。

I couldn't find an ideal solution for this problem, just a partial one. I'll assume you enabled design mode for the panels following the approach in this answer.

Altering the design behavior of the panels requires given them their own designer. Here's a sample class that does this:

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

[Designer(typeof(MyPanelDesigner))]
public class MyPanel : Panel {
    private class MyPanelDesigner : ScrollableControlDesigner {
        public override SelectionRules SelectionRules {
            get { return SelectionRules.None; }
        }
    }
}

Replace the panels in your UC with MyPanel. The custom SelectionRules property ensures that the user cannot easily drag the panel into another position with the mouse. The Location and Size properties are however still editable in the property grid. To get rid of that I think you'll need to override PreFilterProperties().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文