GetExternalDragImage override


#1

I override GetExternalDragImage and returned an object (derived from
GoNode) but the behavior is different than for the default returned by
the base method.

The problem is the alignement of the node: for my object the mouse
pointer is in the left top corner of the object and for the
ExternalDragImage object returned by the
base.GetExternalDragImage the mouse pointer is on the center of
the object.

Any idea what I must do to obtain the same behavior?

Thank you for any help.


#2

You can use GoSelection.HotSpot to figure out the offset from the mouse to GoSelection.Primary.Position.
How are you going to handle multiple objects in the selection?


#3

I do not have multiple selection in my case.

What I want is to drag an object from a palette and to put it in the
view. The dragged image must be different then the one in pallete. Only
one object can be dragged at a time from the palette.

Where do I must use the HotSpot stuff?

My code is something like this:


protected override GoObject GetExternalDragImage(DragEventArgs evt)

{

GoSelection sel = evt.Data.GetData(typeof(GoSelection))
as GoSelection;
if( sel != null )
{
if( some condition for sel.First)
{
create and return a new GoObject
}
}

base.GetExternalDragImage (evt);<br style="font-family: courier new,courier,mono;">

}


#4
GoView.GetExternalDragImage actually returns an instance of: internal class ExternalDragImage : GoImage { public ExternalDragImage() {} public override PointF Location { get { return new PointF(this.Left + myOffset.Width, this.Top + myOffset.Height); } set { this.Position = new PointF(value.X - myOffset.Width, value.Y - myOffset.Height); } } public SizeF Offset { get { return myOffset; } set { myOffset = value; } } private SizeF myOffset = new SizeF(0, 0); } This part of what GetExternalDragImage does: ExternalDragImage img = new ExternalDragImage(); img.Image = bmp; SizeF offset = GoTool.SubtractPoints(primary.Position, bounds.Location); img.Offset = new SizeF(offset.Width + clipsel.HotSpot.Width, offset.Height + clipsel.HotSpot.Height); return img;

#5

Unfortunatelly I can not create an ExternalDragImage and my object does not have an Offset property (nor the GoImage have).
Even if I make the Offset property will not work.
I do not see any solution to this…


#6

I don’t see why you can’t override Location.


#7

Ok I think I got it. I will try. Thanks.


#8

Where i should put the code below? , or in GoView ?

ExternalDragImage img = new ExternalDragImage();
img.Image = bmp;
SizeF offset = GoTool.SubtractPoints(primary.Position, bounds.Location);
img.Offset = new SizeF(offset.Width + clipsel.HotSpot.Width, offset.Height + clipsel.HotSpot.Height);
return img;


#9

suwit, the code was just an example you can not use directly. The class
ExternalDragImage is an internal class of the GoDiagram library and can
not be instantiated from your code.

The proper way to do it is to build you own class (derived from an
GoDiagram object) that has an Offset property and overrides the
Location property.

Then the code must be put in GoView.GetExternalDragImage (you will have to override this method).


#10

I need a sample on this , i’m new for this tools , my part doing drag&drop application diagram, by drag from listview and drop on GoView, i also have a problem when dragged the icon not show. it’s just show default icon.


#11

Several of the sample applications demonstrate handling a drop from a TreeView; dealing with a drop from a ListView shouldn’t be much different. Look for overrides of the GoView.DoExternalDrop method–that’s the method where you can decide what kind of object(s) to add to the view’s GoDocument, including which icon(s), if any.