Search code examples
c#.netdesign-surface

Catching mouse move


Situation :

I'm currently working a project where the aim is to develop a VS-like IDE, where users can drap/drop new controls to a design surface, and modify properties of these controls.

So i implemented IDesignerHost, IServiceContainer, IContainer, IComponentChangeService, and some others useful interface, made to design that.

Everything works fine, i've my toolbox, my design surface, and my propertyGrid working just fine.

Problem is :

Attached to the drag'n'droped controls is a label, which has to follow the control while the user move it with his mouse.

I tried to use the LocationChanged event of the controls, to move the label when the control move. But this event occurs only one time, after the control has moved so the label doesn't move while the control move.

I'm not able to find a way for make this work. Does anyone have any good ideas please ?

Thank you

Edit : I use a custom class, implementing IDesignerHost. Controls on this design surface doesn't fire events Mouse----- (e.g. : MouseDown, MouseMove).


Solution

  • I finally found how to do it :

    I implemented ISelectionService and in the SetSelectedComponents function, I managed to select the label control associated with any selected control.

    I overrided the designer of the label, so that no border/resize-rectangle would show when the label is selected.

    This is a not very elegant solution, but it works well =).