Calculating the drop point

Hello,

I have GoDiagram objects in GoPalette and I am dragging and dropping
on to the Goview. But what I am observing is that they are not getting drawn on actual drop point and some where else. I could figure out it
and added following lines of code for converting drop point in the event handler.
Point screenPnt = new Point(evt.X, evt.Y);
Point viewPnt = PointToClient(screenPnt);
PointF docPnt = ConvertViewToDoc(viewPnt);
Now Dropped objects are drawn almost at correct place. But there is slight shift. As user can hold mouse on any position within the bounds of GoDiagram object in Palette while dragging and drop it on view, I am not able to adjust accurately top left corner of object to be drawn on view so that there is no slightest shift. COuld you please help me to calculate this offset so that object is drawn accurately at the dropped point.
Thanks and Have a nice day,
Nagaraj.

You shouldn’t have to set any properties, implement any event handlers, nor override any methods for users to be able to drag objects from a GoPalette (or any other GoView) to a GoView.

So I don't understand why you have any code at all.
The only customization that is sometimes needed is implementing a GoView.ExternalObjectsDropped event handler that is invoked after a drop from another control. Typically this is for fixing up the dropped objects, held in the GoView.Selection, to make sure they are initialized the way your application wants instead of just copying them from the GoPalette.

Hello Walter,

I agree with you that no code is required. But I have requirement that
When a object is dragged into view from palette, view should be just notifed of dropped object and dropped object should not be drawn on the view. The view will do some processing depending upon type of object dropped and draw a customized type of dropped object. To implement this I have done the following:
1> Overriden DoExternalDrop in my customView class derived from GoView.
protected override IGoCollection DoExternalDrop(DragEventArgs evt) {
return null;
}
In My Windows Form class which hosts this cutom GoView I have subscribed to dragdrop event of GoView.
private void goView1_DragDrop(object sender, DragEventArgs e) { GoSelection goSelection = e.Data.GetData(typeof(GoSelection)) as GoSelection; GoObject goObject = goSelection.Primary; goObject = this.goView1.Selection.Primary; Point screenPoint = new Point(e.X, e.Y); Point viewPoint = PointToClient(screenPoint); PointF docPoint = this.goView1.ConvertViewToDoc(viewPoint);
It is here that I need the information to accurately draw goobject accurately at drop point.
Is my approach correct. How to calculate top left location point of new object which will be drawn in this event handler?

Your point calculations look right.

Instead of overriding (disabling) GoView.DoExternalDrop, I suggest that you implement a GoView.ExternalObjectsDropped event handler that iterates over the selection, creates whatever replacements objects you want in whatever manner you want, and then deletes those selected dropped objects. You can then select your new special objects.

Hello Walter,

Thanks for your reply. I will try this.
Regarding calculation of drop point, I still see some small shift even after this calculation. After some trials I figured out it is equivalent to distance between position of mouse pointer on the drag image to the top-left corner of drag image. I serached for this calculation method in the forum and found something which uses
SizeF offsetSize = this.Selection.HotSpot;
// calculate topleft position point for the new object to be drawn
Point effectiveDropPoint = new Point((int)(documentPoint.X - offsetSize.Width), (int)(documentPoint.Y - offsetSize.Height));
I do not know this is the correct way of doing but while debugging I found offsetSize always zero. Could you please suggest how to calculate this?

You’re getting into the more subtle aspects of the GoDiagram implementation. That’s why it’s generally wisest to use as much of what we offer as you can.

Shouldn't you be looking at the source view's (GoPalette in this case) Selection.HotSpot?

Thanks Walter. I used Goselection object’s hot spot that comes with the
DragEventArgs in DoExternalDrop and it solved the problem. We will try to use GoDiagram features as much as possible. But as our requirements are ever changing, there will be some special cases where we have to do some tweaking.

Thanks again for your help,
Nagaraj.