Canceling a connection between two shapes.


Author
Message
Yeejun Choi
Yeejun Choi
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)
Group: Forum Members
Posts: 2, Visits: 1
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?
Nevron Support
Nevron Support
Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)
Group: Administrators
Posts: 3.1K, Visits: 4.2K

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);

}



Best Regards,
Nevron Support Team


Yeejun Choi
Yeejun Choi
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)
Group: Forum Members
Posts: 2, Visits: 1
Thanks for your apply.

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

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search