Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Preventing links of the same color be drawn more than once between diagram nodes (Read 1887 times)
Ismail
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 9
Joined: Dec 11th, 2020
Preventing links of the same color be drawn more than once between diagram nodes
Dec 22nd, 2020 at 9:52pm
Print Post  
I have several nodes and red, green and blue color links between them.

If I already have a red colored link between two nodes, how can I stop the 2nd red colored link be drawn between these two nodes?

I don't want to let the link be drawn first and remove it later, I want the second red link be stopped before drawn.

I looked at the NodeLinkCreating event, but without knowing the destination node, I don't know how to process.

Any help will be greatly appreciated.

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


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Preventing links of the same color be drawn more than once between diagram nodes
Reply #1 - Dec 23rd, 2020 at 8:00am
Print Post  
Hi,

The destination node is provided as event argument -

Code
Select All
void OnLinkCreating(object sender, LinkValidationEventArgs e)
{
	if (e.Destination == null)
		return;

	e.Cancel =
		GetCommonLinks(e.Origin, e.Destination).
		Select(l => l.Pen.Color == e.Link.Pen.Color).
		Count() > 0;
}

DiagramLinkCollection GetCommonLinks(DiagramNode node1, DiagramNode node2)
{
	DiagramLinkCollection commonLinks = new DiagramLinkCollection();

	foreach (DiagramLink link in node1.OutgoingLinks)
		if (link.Destination == node2)
			commonLinks.Add(link);

	foreach (DiagramLink link in node1.IncomingLinks)
		if (link.Origin == node2)
			commonLinks.Add(link);

	return commonLinks;
} 



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Ismail
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 9
Joined: Dec 11th, 2020
Re: Preventing links of the same color be drawn more than once between diagram nodes
Reply #2 - Dec 23rd, 2020 at 12:49pm
Print Post  
Perfect!
Thanks so much for a fast response.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint