We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to determine connected symbols?

Hi,

I want to do the following:
when user connects 2 symbols using linktool, I need to check which symbols are connected and allow or deny this link, using some criteria.

I've tried to use ConnectionsChanging event, but
Connection.SourcePort and Connection.TargetPort do not contain the source and target symbols simultaneously in one call...



3 Replies

J. J.Nagarajan Syncfusion Team March 1, 2007 05:59 PM UTC

Hi Ok,

The symbols connected with each other can be obtained using the following code snippet

private void diagram1_NodeDoubleClick(object sender, Syncfusion.Windows.Forms.Diagram.NodeMouseEventArgs evtArgs)
{
// To find which shape is connected to other shape
if (evtArgs.Node is Symbol)
{
Symbol symbol = evtArgs.Node as Symbol;
foreach(IGraphEdge edge in sym.Edges)
{
if(edge is Link)
{
Link link=edge as Link;
Symbol symbol1=link.FromNode as Symbol;
Symbol symbo2=link.ToNode as Symbol;
if(evtArgs.Node==symbo2)
MessageBox.Show(symbo2.Name+ " " + "connected to"+ " "+ symbo1.Name);

if(evtArgs.Node==symbo1)
MessageBox.Show(symbo1.Name +" "+ "connected to" + " "+symbo2.Name);
}
}
}
}

I have attached a sample that demonstrates all these features.

Please do the following to run the sample

1. Execute the attached sample.
2. Click "Add Symbols" button to draw the custom symbols.
3. Click LinkSuppor->Link menu item to activate the link tool.
4.Connect the link between two symbols and when you double click on the connected symbol, a MessageBox will show up, whether the symbol is connected or not.

You can down load the sample from the following html page.

http://websamples.syncfusion.com/samples/Diagram.Windows/F57324/main.htm

Please let me know if you have any questions.

Thanks,
Nagaraj


AD Administrator Syncfusion Team March 2, 2007 09:19 AM UTC

Thanks,
but I do not want ask user to double click symbol in order to check which link he has just added.
What the earliest possible event allows me determine connected nodes?


J. J.Nagarajan Syncfusion Team March 2, 2007 11:24 PM UTC

Hi Ok,

You can use the Diagram's ConnectionsChanging() event to do what you are seeking. Please refer to the following code snippet

Symbol sym1;
Symbol sym2;

private void diagram1_ConnectionsChanging(object sender, Syncfusion.Windows.Forms.Diagram.ConnectionCollectionEventArgs evtArgs)
{
if (evtArgs.Connection.SourcePort.GetType()==typeof(AnchoredPort))
{
this.textBox1.Text = (evtArgs.Connection.SourcePort.Parent.Name);
symbol1=evtArgs.Connection.SourcePort.Parent as Symbol;
}

if (evtArgs.Connection.TargetPort.GetType()==typeof(AnchoredPort))
{
this. textBox2.Text = (evtArgs.Connection.TargetPort.Parent.Name);
symbol2=evtArgs.Connection.TargetPort.Parent as Symbol;
}

if(symbol1.Name=="MySymbol")
{
evtArgs.Cancel=false;

}
else
{
evtArgs.Cancel=true;
MessageBox.Show("Connection Invalid");
}
}

I have attached the sample for your reference. In this sample you can get the source and destination nodes after creating the links. You can see the Name of the connected Nodes in the textbox.

Also you can allow or deny this link if the symbol1.Name is "MySymbol".

You can download this sample from the following link.

http://websamples.syncfusion.com/samples/Diagram.Windows/ConnectedSymbols/main.htm

Please refer to this sample and let me know if you have any questions

Thanks,
Nagaraj

Loader.
Live Chat Icon For mobile
Up arrow icon