Default protection for new shapes in a document


https://www.nevron.com/Forum/Topic8460.aspx
Print Topic | Close Window

By David Dieffenthaler - 10 Years Ago
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 David Dieffenthaler - 10 Years Ago
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;
}
}
By Nevron Support - 10 Years Ago

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;

}