开发者

Design-time moving of a child control owned by a composite user control

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 w开发者_Python百科ant 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. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜