views:

223

answers:

1

Hi,

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.

A: 

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.

Ciwee
Thanks, but I think you might have misunderstood the situation a bit. :) The child controls are created by the parent control, and the control does not support adding child controls -- it merely allows the properties of the children to be edited. I'm not quite seeing how intercepting the Changed/Removed events will help me here.
Rytmis
@Rytmis: What I would like to happen is that when a child control is dragged in the designer, the drag actually moves the parent. -> Whenever a child control is removed from the parent control and added to another one (which is detected by the ComponentRemoved/ComponentAdded event) move the parent control as well.
Ciwee