Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic DragDrop from one FC to another... (Read 2438 times)
blazetopher
YaBB Newbies
*
Offline



Posts: 9
Joined: Dec 27th, 2006
DragDrop from one FC to another...
Feb 14th, 2007 at 4:59pm
Print Post  
Hi!  From other posts and just messing around, I'm very close to making this work properly.  However I'm running into a couple of issues that I can't seem to clear up.

Essentially I have two flowchart controls on one form.  When one is disabled, boxes on that control can be dragged and dropped on the second flowchart.

Here's the pertinent code:
Code
Select All
	  private void flowChart2_DragOver(object sender, DragEventArgs e)
	  {
		e.Effect = DragDropEffects.Copy;
	  }

	  private void flowChart2_DragDrop(object sender, DragEventArgs e)
	  {
		PointF pF = flowChart2.ClientToDoc(new Point(e.X, e.Y));

		if (e.Data.GetDataPresent(typeof(Box)))
		{
		    Box tb = (Box)e.Data.GetData(typeof(Box));
		    //tb.Move(pF.X, pF.Y);
		    flowChart2.Objects.Add(tb);

		    flowChart2.Refresh();
		}
	  }

	  private void flowChart1_MouseDown(object sender, MouseEventArgs e)
	  {
		if (flowChart1.Behavior == BehaviorType.DoNothing)
		{
		    PointF pF = flowChart1.ClientToDoc(new Point(e.X, e.Y));
		    Box b = flowChart1.GetBoxAt(pF);

		    if (b == null) return;
		    DoDragDrop(b, DragDropEffects.Copy);
		}
	  } 



Here are my problems:

1.)  If there are arrows connected to the original box, they are also copied, but are only visible when the box in the second FC is selected.  Also, the arrow isn't selectable.  I DON'T want any connected arrows to transfer - only the box.

2.)  I can't get the box to drop where the users mouse is. The //tb.Move(pF.X, pF.Y); was my attempt at this, but it offset the placement of the shape in the second FC, and deleted it from the top FC!!

3.)  If one of the "drag/dropped" boxes in the second FC is selected and moved, the application crashes.


Can you help me with this??

Thanks in advance,
Blaze
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: DragDrop from one FC to another...
Reply #1 - Feb 14th, 2007 at 6:15pm
Print Post  
Hi!

Quote:
1.)  If there are arrows connected to the original box, they are also copied, but are only visible when the box in the second FC is selected.  Also, the arrow isn't selectable.  I DON'T want any connected arrows to transfer - only the box.


Try adding a copy of the dragged box instead of the original box. E.g. use the Box(Box prototype) constructor. Otherwise you will have the same box in both flowcharts. But when you select a box, it is drawn on top of other items together with its arrows - that's so because users can see easier what they would modify if they start to drag the box - and in that case the arrows from the first flowchart will be drawn in the second one.

Quote:
2.)  I can't get the box to drop where the users mouse is. The //tb.Move(pF.X, pF.Y); was my attempt at this, but it offset the placement of the shape in the second FC, and deleted it from the top FC!!


The .NET drag-and-drop events give you the screen coordinates of the mouse. You can convert them to logical like this:

PointF pF = flowChart2.ClientToDoc(flowChart2.PointToClient(new Point(e.X, e.Y)));

Quote:
3.)  If one of the "drag/dropped" boxes in the second FC is selected and moved, the application crashes.


Try using

flowChart2.Add(tb);

instead of

flowChart2.Objects.Add(tb);

Otherwise the control might be in an inconsistent  state, because adding a box to FlowChart.Objects won't automatically add it to FlowChart.Boxes.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
blazetopher
YaBB Newbies
*
Offline



Posts: 9
Joined: Dec 27th, 2006
Re: DragDrop from one FC to another...
Reply #2 - Feb 14th, 2007 at 6:51pm
Print Post  
Excellent - Thank you!  Your suggestions fixed problems 1 & 2 perfectly.  Now the boxes will drag/drop without arrows and the application doesn't crash when I move the dropped boxes.

I'm still having trouble with the position of the dropped box though.  Here is the DragDrop method:

Code
Select All
	  private void flowChart2_DragDrop(object sender, DragEventArgs e)
	  {
		PointF pF = flowChart2.ClientToDoc(new Point(e.X, e.Y));

		if (e.Data.GetDataPresent(typeof(Box)))
		{
		    Box tb = (Box)e.Data.GetData(typeof(Box));
		    Box b = new Box(tb);
		    b.Move(pF.X, pF.Y);

		    flowChart2.Add(b);
		    label1.BackColor = Color.Red;
		    flowChart2.Refresh();
		}
	  } 



The dropped box ends up shifted quite a bit down and slightly to the right of where it's dropped.  If I comment out the "b.move(pF.X, pF.Y)" line, then the box is dropped in the same location that the original was (but on the second flowchart), regardless of where the mouse is.

What am I doing incorrectly?  By the way, both flowcharts are set up with the exact same properties.

Thanks again,
Blaze
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: DragDrop from one FC to another...
Reply #3 - Feb 15th, 2007 at 6:14am
Print Post  
Hi,

You get screen coordinates in the DragDrop event handler. Just replace

PointF pF = flowChart2.ClientToDoc(new Point(e.X, e.Y));

with

PointF pF = flowChart2.ClientToDoc(flowChart2.PointToClient(new Point(e.X, e.Y)));

and you will get correct document coordinates.

Stoyan
  
Back to top
 
IP Logged
 
blazetopher
YaBB Newbies
*
Offline



Posts: 9
Joined: Dec 27th, 2006
Re: DragDrop from one FC to another...
Reply #4 - Feb 15th, 2007 at 11:20am
Print Post  
Great, thank you.  Sorry about the redundant question - I didn't look carefully enough at your advice from your first reply.

Thanks again,
Blaze
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint