|
|
|
date: Thu, 29 May 2008 08:46:01 -0700,
group: microsoft.public.visio.developer
back
Creating custom shapes using Drag&Drop
Hi,
I have a tree view with my model elements as an anchor window. When a model
element from this tree view is dragged on the page, a new shape should be
created that has some model-specific information attached (e.g. the ID of the
model element).
The code on the drag source side is like this:
private void modelStructureTree_ItemDrag(object sender, ItemDragEventArgs
e){
TreeNode draggedNode = e.Item as TreeNode;
object modelObject = draggedNode.Tag;
Master master = getMasterForObjectType(modelObject.GetType());
Shape shape = master.Shapes[1];
DoDragDrop(shape, DragDropEffects.Move);
}
I cannot attach the model element ID to "shape" because "shape" is the
master shape, and not a shape that has been created from the master (this
happens when the shape is dropped, I guess).
So, I
1.) Either need to instantiate a shape on the drag source side. Can I create
a shape "in memory", without dropping it on a page, and pass it to
DoDragDrop()?
2.) Or access the dropped object on the drop target side (in the event
handler for visEvtCodeMouseMove). But I don't see any property for the
Drag&Drop data transfer object in Visio's MouseEvent object. Moreover, when I
pass a custom object (and not a shape) to DoDragDrop() on the drag source
side, dropping the object will be refused by Visio and no visEvtCodeMouseMove
event that represents a drop will be generated at all.
So, how can I create shapes which reference their model elements by
drag&drop from an anchor window?
Regards,
Niklas
date: Thu, 29 May 2008 08:46:01 -0700
author: Niklas Deutschmann
Re: Creating custom shapes using Drag&Drop
I would go for option 2 (or rather I have done several times)
You can set an ItemForDrag (or similar) when the drag is commenced from the
treeview, then when the new shape is created (using the ShapeAdded event),
set the new shape properties from this ItemForDrag object.
"Niklas Deutschmann" wrote in
message news:37142023-5964-425D-B0F9-D02D678869A5@microsoft.com...
> Hi,
>
> I have a tree view with my model elements as an anchor window. When a
> model
> element from this tree view is dragged on the page, a new shape should be
> created that has some model-specific information attached (e.g. the ID of
> the
> model element).
>
> The code on the drag source side is like this:
>
> private void modelStructureTree_ItemDrag(object sender, ItemDragEventArgs
> e){
> TreeNode draggedNode = e.Item as TreeNode;
> object modelObject = draggedNode.Tag;
> Master master = getMasterForObjectType(modelObject.GetType());
> Shape shape = master.Shapes[1];
> DoDragDrop(shape, DragDropEffects.Move);
> }
>
> I cannot attach the model element ID to "shape" because "shape" is the
> master shape, and not a shape that has been created from the master (this
> happens when the shape is dropped, I guess).
>
> So, I
> 1.) Either need to instantiate a shape on the drag source side. Can I
> create
> a shape "in memory", without dropping it on a page, and pass it to
> DoDragDrop()?
>
> 2.) Or access the dropped object on the drop target side (in the event
> handler for visEvtCodeMouseMove). But I don't see any property for the
> Drag&Drop data transfer object in Visio's MouseEvent object. Moreover,
> when I
> pass a custom object (and not a shape) to DoDragDrop() on the drag source
> side, dropping the object will be refused by Visio and no
> visEvtCodeMouseMove
> event that represents a drop will be generated at all.
>
> So, how can I create shapes which reference their model elements by
> drag&drop from an anchor window?
>
> Regards,
> Niklas
>
--
David Parker
Microsoft MVP (Visio)
http://bvisual.spaces.live.com
http://www.visualizinginformation.com
date: Sun, 1 Jun 2008 21:38:46 +0100
author: David Parker
Re: Creating custom shapes using Drag&Drop
On 2 ÉÀÎ, 15:02, Niklas Deutschmann
wrote:
> Hi David,
>
> > I would go for option 2 (or rather I have done several times)
> > You can set an ItemForDrag (or similar) when the drag is commenced from the
> > treeview, then when the new shape is created (using the ShapeAdded event> > set the new shape properties from this ItemForDrag object.
>
> Could you maybe go into some more detail? I can't find this property or any
> similarly named property or object in the documentation, and I would really
> like to know how to access the drag&drop data exchange object when handling a
> drop event.
>
> Regards,
> Niklas
I think what is actually meant, that before calling DoDragDrop,
you can set some "global" variable that will "hold" the node you are
dragging.
Also, you could create an event handler for Visio's "shape added"
event (visEvtShape븫Ҿ퀝).
And in that "shape added" event handler, you could just use that
variable to initialize the (new) shape
(the shape being dropped is passed in as an argument to that event
handler).
And, IMHO there is no point in using that "mouse move" event you
mentioned.
Kind regards, Nikolay.
date: Tue, 3 Jun 2008 06:49:28 -0700 (PDT)
author: Nikolay Belyh
Re: Creating custom shapes using Drag&Drop
I agree, and I should also add that I got my original code from Graham
Wideman's book, http://diagramantics.com/ or
http://www.amazon.com/Visio-2003-Developers/dp/1412011124/ref=sr_11_1?ie=UTF8
"Nikolay Belyh" wrote in message
news:e131fd0c-387a-4d0b-b481-3a43d6a0e849@d45g2000hsc.googlegroups.com...
On 2 ÉÀÎ, 15:02, Niklas Deutschmann
wrote:
> Hi David,
>
> > I would go for option 2 (or rather I have done several times)
> > You can set an ItemForDrag (or similar) when the drag is commenced from
> > the
> > treeview, then when the new shape is created (using the ShapeAdded
> > event),
> > set the new shape properties from this ItemForDrag object.
>
> Could you maybe go into some more detail? I can't find this property or
> any
> similarly named property or object in the documentation, and I would
> really
> like to know how to access the drag&drop data exchange object when
> handling a
> drop event.
>
> Regards,
> Niklas
I think what is actually meant, that before calling DoDragDrop,
you can set some "global" variable that will "hold" the node you are
dragging.
Also, you could create an event handler for Visio's "shape added"
event (visEvtShape+visEvtAdd).
And in that "shape added" event handler, you could just use that
variable to initialize the (new) shape
(the shape being dropped is passed in as an argument to that event
handler).
And, IMHO there is no point in using that "mouse move" event you
mentioned.
Kind regards, Nikolay.
--
David Parker
Microsoft MVP (Visio)
http://bvisual.spaces.live.com
http://www.visualizinginformation.com
date: Wed, 4 Jun 2008 09:19:16 +0100
author: David Parker
|
|