复合用户控件拥有的子控件的设计时移动

发布于 2024-08-15 12:31:15 字数 279 浏览 4 评论 0原文

我有一个 Windows 窗体用户控件,该控件(由于与此问题无关的各种原因)在设计器中公开,非常类似于拆分面板中的面板。除了拖动控件之外,大多数事情都运行良好。子控件由用户控件创建,并且不接受新的子控件。目的只是允许编辑预定义子项的属性。

由于控件允许设计子控件,因此也可以在设计器中选择它们(这是一件好事,我不想改变这一点)。但是,它们不能也不应该单独移动。

我希望发生的是,当在设计器中拖动子控件时,拖动实际上会移动父控件。

我一直在浏览有关控件设计器的文档,但没有出现任何简单或明显的内容。

I have a Windows Forms user control, which (for various reasons irrelevant to this issue) are exposed in the designer, much like the panels in a split panel. Most everything works nicely, except for dragging the control. The child controls are created by the user control, and it does not accept new children. The intent is only to allow the properties of the predefined children to be edited.

Since the control allows the child controls to be designed, they can also be selected in the designer (this is a good thing, and I don't want to change this). However, they can not and should not be moved individually.

What I would like to happen is that when a child control is dragged in the designer, the drag actually moves the parent.

I've been skimming the documentation on control designers, but nothing popped up that would be simple or obvious.

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

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

发布评论

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

评论(1

浮世清欢 2024-08-22 12:31:15

尝试这个并告诉我会发生什么:

  1. 扩展 UserControl 类
  2. 定义一个从默认 UserControl 设计器类(我猜是 UserControlDocumentDesigner)派生的新 ControlDesigner 类
  3. 在此设计器中将其写入初始化方法重写中:

    IComponentChangeService changeService = this.GetService(typeof(IComponentChangeService));
    changeService.ComponentRemoved += new ComponentEventHandler(changeService_ComponentRemoved);

您现在可以放置有关删除控件时发生的情况的逻辑。请记住,不仅仅是从用户控件中删除的控件会触发此事件。您必须检查这一点,并且您不需要忘记 ComponentChanging 和 ComponentChanged 事件,以便使思考在设计时正常工作。

Try this and tell me what happens:

  1. Extend UserControl class
  2. Define a new ControlDesigner class deriving from the default UserControl designer class (UserControlDocumentDesigner I guess)
  3. Within this designer write this inside the initialize method override:

    IComponentChangeService changeService = this.GetService(typeof(IComponentChangeService));
    changeService.ComponentRemoved += new ComponentEventHandler(changeService_ComponentRemoved);

you can now place logics about what happens when a control is removed. Remember that not just controls removed FROM your user control will fire this event. You have to check for that and also you need not to forget about the ComponentChanging and ComponentChanged events in order to make thinks work fine at design-time.

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