Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How to do drag&drop from a FlowChart Control (Read 2536 times)
debut
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 3
Joined: Dec 4th, 2008
How to do drag&drop from a FlowChart Control
Dec 16th, 2008 at 1:03am
Print Post  
How to do drag&drop from a FlowChart Control to the FlowChart Control?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to do drag&drop from a FlowChart Contr
Reply #1 - Dec 16th, 2008 at 3:10pm
Print Post  
This starts drag-and-drop when Shift is down:

Code
Select All
private void diagViewL_MouseMove(object sender, MouseEventArgs e)
{
	if (e.Button != MouseButtons.Left)
		return;

	if ((Control.ModifierKeys & Keys.Shift) == 0)
		return;

	DiagramNode node = diagL.GetNodeAt(diagViewL.ClientToDoc(e.Location));
	if (diagL.Interaction != null)
		diagL.Interaction.Cancel(diagL);

	if (diagL.Selection.Nodes.Count > 1)
	{
		Diagram diagTemp = new Diagram();
		SelectionCopy copy = diagL.CopySelection(diagL, false, false);
		diagTemp.PasteSelection(diagTemp, copy, null, 0, 0);

		DoDragDrop(diagTemp.SaveToString(), DragDropEffects.Copy);
	}
	else if (node != null && node is ShapeNode)
	{
		DoDragDrop(node as ShapeNode, DragDropEffects.Copy);
	}
}

private void diagViewR_DragOver(object sender, DragEventArgs e)
{
	if (e.Data.GetDataPresent("System.String"))
	{
		e.Effect = DragDropEffects.Copy;
	}
	else if (e.Data.GetDataPresent("MindFusion.Diagramming.ShapeNode"))
	{
		e.Effect = DragDropEffects.Copy;
	}
	else
	{
		e.Effect = DragDropEffects.None;
	}
}

private void diagViewR_DragDrop(object sender, DragEventArgs e)
{
	if (e.Data.GetDataPresent("System.String"))
	{
		string s = e.Data.GetData("System.String") as string;
		Diagram diagTemp = new Diagram();
		diagTemp.LoadFromString(s);
		SelectionCopy copy = diagTemp.CopySelection(diagTemp, false, false);

		PointF pt = diagViewR.ClientToDoc(Control.MousePosition);
		diagR.PasteSelection(diagR, copy, null, 0, 0);
	}
	else if (e.Data.GetDataPresent("MindFusion.Diagramming.ShapeNode"))
	{
		if (e.Effect == DragDropEffects.Copy)
		{
			ShapeNode node = e.Data.GetData("MindFusion.Diagramming.ShapeNode") as ShapeNode;

			Point p = diagViewR.PointToClient(new Point(e.X, e.Y));
			PointF pt = diagViewR.ClientToDoc(new Point(p.X, p.Y));

			diagR.Nodes.Add(new ShapeNode(node));
			MessageBox.Show(diagL.Nodes.Count.ToString());
		}
	}
}
 



I don't know why our developer added the diagL.Selection.Nodes.Count == 1 case at all; the CopySelection method should work just fine with a single selected node.

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


I love YaBB 1G - SP1!

Posts: 3
Joined: Dec 4th, 2008
Re: How to do drag&drop from a FlowChart Contr
Reply #2 - Dec 17th, 2008 at 7:00am
Print Post  
thanks!
1. after drog one node to diagR, the status of mouse is down on diagL, i move mouse on diagL, it begin to select some node, no mousedown or click, why?
2. i must press "shift" and move mouse, only mouse, how to do?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to do drag&drop from a FlowChart Contr
Reply #3 - Dec 17th, 2008 at 8:00am
Print Post  
The NodeStartModifying and SelectionMoving events might be better for this:

Code
Select All
private void diagL_NodeStartModifying(object sender, NodeValidationEventArgs e)
{
	if (e.AdjustmentHandle == AdjustmentHandles.Move)
	{
		e.CancelDrag();
		DoDragDropSelection();
	}
}

private void diagL_SelectionMoving(object sender, ValidationEventArgs e)
{
	DoDragDropSelection();
}

private void DoDragDropSelection()
{
	Diagram diagTemp = new Diagram();
	SelectionCopy copy = diagL.CopySelection(diagL, false, false);
	diagTemp.PasteSelection(diagTemp, copy, null, 0, 0);

	DoDragDrop(diagTemp.SaveToString(), DragDropEffects.Copy);
}
 



Additionally, use the forum's Search to find the MoveSelection sample method, which you might use in the Drop handler to move the items just copied to the mouse position.

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


I love YaBB 1G - SP1!

Posts: 3
Joined: Dec 4th, 2008
Re: How to do drag&drop from a FlowChart Contr
Reply #4 - Dec 17th, 2008 at 9:36am
Print Post  
it's right work
thank you!
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint