private void OnNodesConnecting(NConnectionCancelEventArgs args) { NDynamicPort port1 = (NDynamicPort)document.GetElementFromUniqueId(args.UniqueId1); NDynamicPort port2 = (NDynamicPort)document.GetElementFromUniqueId(args.UniqueId2); int side1 = GetSideIndex(port1); int side2 = GetSideIndex(port2); bool sidesFail = side1 % 2 != side2 % 2; bool alreadyConnected = port1.ConnectedPoints != null || port2.ConnectedPoints != null; if (sidesFail || alreadyConnected) { // The ports cannot be connected, so cancel the connection and apply a bounce back force NPoint offset = new NPoint(0, 0); bool even = side1 % 2 == 0; if (sidesFail) { if (even) { offset.X = (1 - side1) * SIZE; } else { offset.Y = (2 - side1) * SIZE; } } else { if (!even) { offset.X = (2 - side1) * SIZE; } else { offset.Y = (1 - side1) * SIZE; } } port1.Shape.Location = new NPointF(port1.Shape.Location.X + offset.X, port1.Shape.Location.Y + offset.Y); args.Cancel = true; } }
private void EventSinkService_Disconnecting(NConnectionCancelEventArgs args) { LogEvent( "Document: Disconnecting" ); }