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

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

本文介绍了由复合用户控件拥有的子控件的设计时移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows窗体用户控件,这(不相关这一问题的各种原因)被暴露在设计,在分割面板面板很像。大多数都工作得很好,除了拖动控制。该子控件由用户控制创建的,它不接受新的儿童。其意图是仅允许predefined孩子要被编辑的属性。

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.

推荐答案

试试这个,告诉我发生了什么:

Try this and tell me what happens:

  1. 扩展控件类
  2. 定义一个新的ControlDesigner类从默认的用户控件设计类派生(UserControlDocumentDesigner我猜的)
  3. 在这个设计师写这个初始化方法重写里面:

  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 + =新ComponentEventHandler(changeService_ComponentRemoved);

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

您现在可以将有关时,控制被删除会发生什么逻辑。请记住,不只是控制删除了你的用户控件将触发该事件。你必须检查的,你也不必为忘记ComponentChanging和ComponentChanged活动,以使认为做工精细在设计时。

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.

这篇关于由复合用户控件拥有的子控件的设计时移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 01:57