Nevron Forum

Canceling a connection between two shapes.

https://www.nevron.com/Forum/Topic6836.aspx

By Yeejun Choi - Friday, August 17, 2012

We can cancel a connection between two shapes through the Connecting event.

example :

void EventSinkService_Connecting(NConnectionCancelEventArgs args)
{
try
{
var plug = args.Document.GetElementFromUniqueId(args.UniqueId1) as NPlug;
var port = args.Document.GetElementFromUniqueId(args.UniqueId2) as NRotatedBoundsPort;
var connector = plug.Shape as NShape;

if (port.Plugs != null && port.Plugs.Count == 1)
{
args.Cancel = true;
}
}
catch (Exception error)
{
throw error;
}
}

According to things I've got, UniqueId1 is UniqueId of connection plug. And UniqueId2 is a connected port's.
So a shape of plug(UniqueId1) is NLineShape or NBezierCurveShape or NStepConnector.

Anyway, If args.Cancel is set to true, the connection will be cancelled.
However, something is different in appearance.

In case of dragging edges of line, a connection will be cancelled. But, seemingly it just seems to be connected.

How to move a point of connected line?
By Nevron Support - Friday, August 17, 2012

You cannot do this directly, but there is a trick that can help you move the end point of the connector after cancelling the connection. The idea is to use a System.Windows.Forms.Timer and move the plug in a direction of your choice in the timer's Tick event. Here's an example:

document.EventSinkService.Connecting += new ConnectionCancelEventHandler(OnEventSinkServiceConnecting);

 

...

 

private void OnEventSinkServiceConnecting(NConnectionCancelEventArgs args)

{

        NPlug plug = args.Document.GetElementFromUniqueId(args.UniqueId1) as NPlug;

        NPort port = args.Document.GetElementFromUniqueId(args.UniqueId2) as NRotatedBoundsPort;

 

        args.Cancel = true;

 

        Timer timer = new Timer();

        timer.Interval = 100;

        timer.Tag = plug;

        timer.Tick += new EventHandler(OnTimerTick);

        timer.Start();

}

 

private void OnTimerTick(object sender, EventArgs e)

{

        Timer timer = (Timer)sender;

        timer.Stop();

 

        NPlug plug = (NPlug)timer.Tag;

        plug.Location = new NPointF(plug.Location.X, plug.Location.Y - 50);

}

By Yeejun Choi - Monday, August 20, 2012

Thanks for your apply.

It works good.
Is there no way other than it? I usually don't use the System.Windows.Timer.