Aurigma Forums
»
Graphics Mill
»
Discussions – Graphics Mill
»
Add Drag and Drop Capablilities to the objects derived from VObject
Rank: Advanced Member
Groups: Guest
Joined: 9/10/2010(UTC) Posts: 57
Thanks: 1 times
|
Hello,
This may be out of the scope of discussion topics of Graphic Mill. But any suggestion is appreciated:
What is the best approach to adding Drag and Drop Capabilities to the objects derived from VObject?
We have tried to make VObject derived from Window.Form.Control but dropover or dragdrop event is not fired even though we wire the DragEventHandler in the object contructor.
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 1/31/2005(UTC) Posts: 458
Was thanked: 5 time(s) in 5 post(s)
|
Hello,
VObjects are drawn directly to control's surface, they don't exist as separate entities in WinForms hierarchy. Therefore separate VObject cannot handle drag-n-drop events.
Instead, you should handle drag-n-drop events of the MultiLayerViewer control and map screen coordinates to canvas points. After that you can iterate through VObjects and determine which one, for example, received "drop" event using HitTest() method.
|
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 9/10/2010(UTC) Posts: 57
Thanks: 1 times
|
Hello, Alex,
Appreciate the suggestions.
Try to fully understand your suggested approach:
1. Yes, we have dragover and dragdrop event fired for MultilayerViewer. You mean that we should fire a VObject dragover event and dragdrop event by our own coding ( such as calling methods of OnDragOver or OnDragDrop of VObject) within dragover and dragdrop event of MultilayerVewer if that VObject instance test true for its HitTest Method. Or there is no implementation of OnDragOver or OnDragDrop event for VObject at all.
2. We notice that HitTest is called only when the mouse is clicked but not when the mouse is over. The actual situation is that HitTest should be called and test true when the mouse is over the VObject instance ?
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 9/10/2010(UTC) Posts: 57
Thanks: 1 times
|
Hello, Alex,
Well, it seems that it can achieve what we want by simply iterating through VObjects to test HitTest within dragover and dragdrop event method of multiviewer without evoking dragover and dragdrop event for VObject.
But it would be nice if you can further elaborate the discussion of item 1 in our previous reply.
Also, it would be nicer if you can talk about some approaches to implement dragover and dragdrop event for VObject without having VObject derived from Window.Form.Control
Thank you.
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 1/31/2005(UTC) Posts: 458
Was thanked: 5 time(s) in 5 post(s)
|
Hello mzhao,
Yes, you got me right - you should use VObject.HitTest() in your handlers for DragOver and DragDrop events to provide behavior you need. For example, you may return true when some TextVObject is under mouse cursor in DragOver handler and change its Text property in DragDrop handler.
VObject is not (and shouldn't be) derived from Windows.Form.Control, because it has completely different semantics and is not expected to work like such control.
So, I didn't quite understand your first item in the first your replay. Of course, you can add some methods for drag-n-drop support in VObjects if you want. But it is just question of design of your application, but not a common pattern. Sometimes it maybe easier to implement all this logic in MultilayerViewer's drag-n-drop events.
Maybe you could bring some example for your task, so we can discuss it more specifically?
|
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 9/10/2010(UTC) Posts: 57
Thanks: 1 times
|
Hello, Alex,
Appreciate that you spent some time on this discussion.
Following are what we see how to approach this:
1. Agree with you that VObject should not be derived from Window.Form.Control. 2. To have dragdrop capablility be added to VObject, VObject should implement : a. IDragTarget Interface, b. Events associated each method of IDragTarget Interface. 3. There are two possible ways to fire those events a. in the same events of MultiLayerViewer using VObject.HitTest to identify the right VObject instance to fire the related event: something like this:
MultiLayerViewer1_DragDrop (object sender, DragEventArg e) {
Point newPoint = MultiLayerViewer1.PointToClient(new Point((int)e.X, (int)E.Y)); PointF PosicaoNoCanvas = MultiLayerViewer1.ControlToWorkspace(newPoint, Aurigma.GraphicsMill.Unit.Point);
foreach (VObject vo in MultiLayerViewer1.CurrentLayer.VObjects) { if(vo.HitTest (PosicaoNoCanvas, 0.0F)) { vo.OnDragDrop(e); } } }
b. If we want to implement IDragTarget Interface of VObject completely within VObject, is this possible? Then, we need to talk about how to receive the dragdrop data, how create DragEventArg, when and where and how to evoke the event
We are very interested in your input to this second possible way: item b in above.
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 1/31/2005(UTC) Posts: 458
Was thanked: 5 time(s) in 5 post(s)
|
Hello mzhao,
I cannot see how this can be implemented.
Maybe I'm wrong, but here is my thoughts: all drag-n-drop events now are received by MultiLayerViewer. You need to pass that information to VObject. Therefore somewhere in your code you will have to have the same loop you wrote in the previous message. Why not have it in MultiLayerViewer's event handler?
I don't know, maybe there is a possibility to intercept mouse events on the Application level, separate drag-n-drop events from all others and pass them to VObjects directly... But I see no advantages of such approach. Could point me where I'm wrong?
|
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 9/10/2010(UTC) Posts: 57
Thanks: 1 times
|
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 1/31/2005(UTC) Posts: 458
Was thanked: 5 time(s) in 5 post(s)
|
You are welcome! Feel free to post a message here in case of any other questions. |
|
|
|
|
Aurigma Forums
»
Graphics Mill
»
Discussions – Graphics Mill
»
Add Drag and Drop Capablilities to the objects derived from VObject
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.