Nevron Forum

How to remove artifacts after remove connection line?

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

By Maxim Dobryakov - Friday, June 3, 2011

Hello, All

I have implemented functionality to remove connection between two shapes in some cases (see EventSinkServiceOnConnected method in demo project). But it code cause creation of artifacts (see attached picture).

How to remove these artifacts after remove connection line?

For any case I have attached demo project to reproduce problem (rename file before extract from ZIP archive). Just try to connect two shapes to reproduce problem.

Thanks
By Nevron Support - Monday, June 6, 2011

Hi,

The best approach for your scenario is to subscribe to the NodeInserted event of the document’s event sink service, add the created connectors to a list and use a timer to delete those of them you do not need. The following is a simple source code:

 

public MainForm()

{

      // Your initializing code here

      InitializeComponent();

m_Connectors = new List<NRoutableConnector>();

...

 

      // Subscribe to the NodeInserted event

ctlDrawingDocument.EventSinkService.NodeInserted += new ChildNodeEventHandler(EventSinkService_NodeInserted);

 

      // Initialize the timer

      m_Timer = new Timer();

      m_Timer.Interval = 100;

      m_Timer.Tick += new EventHandler(Timer_Tick);

}

 

private void EventSinkService_NodeInserted(NChildNodeEventArgs args)

{

      NRoutableConnector connector = args.Child as NRoutableConnector;

      if (connector != null)

      {

            m_Connectors.Add(connector);

            if (m_Timer.Enabled == false)

            {

                  // Start the processing timer if it is stopped

                  m_Timer.Start();

            }

      }

}

 

private void Timer_Tick(object sender, System.EventArgs e)

{

      // Evaluate the connectors and remove one or more of them based on your logic

      for (int i = 0, count = m_Connectors.Count; i < count; i++)

      {

            NRoutableConnector connector = (NRoutableConnector)m_Connectors[i];

            ctlDrawingDocument.ActiveLayer.RemoveChild(connector);

      }

 

      // Clear the processed connectors and stop the timer

      m_Connectors.Clear();

      m_Timer.Stop();

}

By Maxim Dobryakov - Monday, June 6, 2011

Hello,

Could you please explain hack with Timer? As I understand you use it for postpone removing.

How do you think is it possible to solve problem without timer? It will do my code more unclear.

Thanks