Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How to Create User-defined ShapeNode when Click in the diagram? (Read 1156 times)
heyx
Junior Member
**
Offline


I Love MindFusion!

Posts: 69
Joined: Oct 9th, 2014
How to Create User-defined ShapeNode when Click in the diagram?
Dec 16th, 2014 at 6:33am
Print Post  
hi,I Create several User-defined ShapeNode in my Code and I want to use the toolbar that when I click one button in toolbar(it's mean the related shapenode shoud be created after I click in the diagram)
For example:
I click the "Add New EvElectronicSwitch" button in toolbar,and move the mouse into the diagram and click.then the
"EvElectronicSwitch" Shapenode should be create at the mouse‘s position.
Do you know how to do this?and I attach my project to you for asking for you help. thanks
  

EvSwitch_002.rar (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to Create User-defined ShapeNode when Click in the diagram?
Reply #1 - Dec 16th, 2014 at 8:58am
Print Post  
Hi,

If using standard ShapeNodes, you could set Diagram.DefaultShape from toolbar click handlers, and call Factory.CreateShapeNode from Diagram.Clicked handler:

Code
Select All
Size newNodeSize = new Size(100, 100);

private void OnDiagramClicked(object sender, DiagramEventArgs e)
{
	diagram.Factory.CreateShapeNode(
		e.MousePosition - new Vector(newNodeSize.Width, newNodeSize.Height) / 2,
		newNodeSize);
}

// in toolbar click
diagram.DefaultShape = Shape.FromId("EvElectronicSwitch");
 



If using custom node types, you could keep a prototype node for each type, set a current prototype from toolbar handlers, and handle Diagram.Clicked by call Diagram.Nodes.Add(currentPrototype.Clone());

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint