如何防止容器控件在设计时转移到用户控件中?
我有一个自定义控件,其中包含 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找不到解决这个问题的理想解决方案,只是部分解决方案。我假设您按照 这个答案。
改变面板的设计行为需要给它们自己的设计师。下面是执行此操作的示例类:
将 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:
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().