Page Index Toggle Pages: 1 [2]  Send TopicPrint
Hot Topic (More than 10 Replies) Ways to generate ShapeNode (Read 6670 times)
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Ways to generate ShapeNode
Reply #15 - Sep 7th, 2020 at 9:27am
Print Post  
Quote:
I want to change the style of ShapeNode drawn by Ctrl + mouse to rectangle. How do I achieve this?


The usual way - set the node's properties.

Quote:
I need Ctrl+mouse drawing and Ctrl+double-click to exist and do not affect each other. How do I achieve this?


They already do not affect each other, I can draw both by ctrl mouse drag and double-clicks in my test project.

Quote:
Can Ctrl+double-click also be placed in the custom class RectanglesBehavior?


diagram.DoublClicked += method name in your class;
  
Back to top
 
IP Logged
 
JackPan
Full Member
***
Offline


I Love MindFusion!

Posts: 134
Joined: Apr 9th, 2020
Re: Ways to generate ShapeNode
Reply #16 - Sep 7th, 2020 at 10:37am
Print Post  
Hi, Slavcho Smiley

I don't really understand the role of 2 in the screenshot below. Please explain.

How to change the style of ShapeNode before generating a new ShapeNode in screenshot 1 below?

Now I put the diagram in the MainWindow class. At present, Ctrl+double-click is implemented in diagram_NodeDoubleClicked in MainWindow class; Ctrl+mouse drawing is placed in the new class RectanglesBehavior. How to put Ctrl+double-click and Ctrl+mouse drawing in RectanglesBehavior?
Is this better for program optimization?

Best regards.
  

9_7_0.png ( 176 KB | 80 Downloads )
9_7_0.png
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Ways to generate ShapeNode
Reply #17 - Sep 7th, 2020 at 11:05am
Print Post  
Quote:
How to change the style of ShapeNode before generating a new ShapeNode in screenshot 1 below?


Code
Select All
if (Keyboard.Modifiers == ModifierKeys.Control)
{
	var node = new ShapeNode(Diagram);
	node.Brush = Brushes.Transparent;
	return new InteractionState(node, null, Action.Create);
} 

  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Ways to generate ShapeNode
Reply #18 - Sep 7th, 2020 at 11:09am
Print Post  
Quote:
I don't really understand the role of 2 in the screenshot below. Please explain.


That makes the mouse-drawing operation resize currently selected node if there's adjustment handle at current position.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Ways to generate ShapeNode
Reply #19 - Sep 7th, 2020 at 11:11am
Print Post  
Quote:
How to put Ctrl+double-click and Ctrl+mouse drawing in RectanglesBehavior?


Code
Select All
class RectanglesBehavior : DrawShapesBehavior
{
	public RectanglesBehavior(Diagram diagram) : base(diagram)
	{
		diagram.DoubleClicked += OnDiagramDoubleClicked;
	}

	void OnDiagramDoubleClicked(object sender, DiagramEventArgs e)
	{
		// hold down the Ctrl key + double-click
		if (Keyboard.Modifiers == ModifierKeys.Control)
		{
			var cx = e.MousePosition.X;
			var cy = e.MousePosition.Y;

			var rectangle1 = Diagram.Factory.CreateShapeNode(
				cx - 50, cy - 50, 100, 100, Shapes.Rectangle);

			rectangle1.Brush = Brushes.Transparent;
			rectangle1.Stroke = Brushes.Green;
		}
	}
	...
 

  
Back to top
 
IP Logged
 
JackPan
Full Member
***
Offline


I Love MindFusion!

Posts: 134
Joined: Apr 9th, 2020
Re: Ways to generate ShapeNode
Reply #20 - Sep 7th, 2020 at 11:53am
Print Post  
Hi, Slavcho Smiley

Only one NodeDoubleClicked can exist in the chart. Put it in the MainWindow class or RectanglesBehavior which is better for program optimization?

Best regards.
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Ways to generate ShapeNode
Reply #21 - Sep 8th, 2020 at 5:17am
Print Post  
I'm not sure what you mean by that, you can have many handlers in different classes for same event. For performance it doesn't matter where you keep your event handlers, just might help you arrange the code a bit with all mouse handling in one place.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
JackPan
Full Member
***
Offline


I Love MindFusion!

Posts: 134
Joined: Apr 9th, 2020
Re: Ways to generate ShapeNode
Reply #22 - Sep 8th, 2020 at 6:46am
Print Post  
Thank you very much, Slavcho Smiley

Best regards. Smiley Smiley Smiley
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1 [2] 
Send TopicPrint