Nevron Forum

Default protection for new shapes in a document

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

By David Dieffenthaler 1 - Thursday, February 6, 2014

Hello,

As it is possible to set default styles for shapes using NDrawingDocument.Style attribute, is it possible to define default protections for the shapes we are drawing?

Maybe I could use one of the event in the EventSinkService to know when a new shape is added and set the protections at this point?

Thanks
David
By Nevron Support - Friday, February 7, 2014

Hi, in your case it is best to apply the protections when the shape is added to the doucment, i.e. in the NodeInserted event of the document's event sync service:

document.EventSinkService.NodeInserted += OnNodeInserted;

 

private void OnNodeInserted(NChildNodeEventArgs args)

{

      NShape shape = args.Child as NShape;

      if (shape == null)

            return;

 

      // Set protections

      NAbilities protection = shape.Protection;

      protection.Select = true;

      shape.Protection = protection;

}

By David Dieffenthaler 1 - Friday, February 7, 2014

Found one answer for doing this:

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

and

void EventSinkService_NodeInserted(NChildNodeEventArgs args)
{
INNode child = args.Child;

if (child is NRoutableConnector && child as NRoutableConnector != null)
{//we just added a connector
NRoutableConnector edge = child as NRoutableConnector;
NAbilities protection = new NAbilities();
protection.MoveX = true;
protection.MoveY = true;
edge.Protection = protection;
}
}