//Occurs when an element is added to the elements collection private void Element_Insert(object sender, ElementsEventArgs e) { Element element = e.Value; //Set the layer element.SetLayer(Layer); //Set handlers element.ElementInvalid += new EventHandler(Element_ElementInvalid); //Set the container element.SetContainer(Container); CreateRenderList(); OnElementInvalid(); }
//Occurs when an element is added to the elements collection private void Element_Insert(object sender, ElementsEventArgs e) { Element element = e.Value; if (element is Group) { throw new GroupException("A group cannot be added to another group."); } //Set the layer if not already set //Deserialized elements have layer information set if (element.Layer == null && Layer != null) { Layer layer = Layer; element.SetLayer(layer); //Add to the default level string key = layer.Elements.CreateKey(); layer.Elements.SetModifiable(true); layer.Elements.Add(key, element); layer.Elements.SetModifiable(false); //Set the layer key element.SetLayerKey(key); //Set the element z order element.mZOrder = layer.Elements.Count; if (element is IUserInteractive) { IUserInteractive interactive = (IUserInteractive)element; if ((interactive.Interaction & UserInteraction.BringToFront) == UserInteraction.BringToFront) { layer.Elements.BringToFront(element); } } } //Set the container element.SetContainer(this); //Set handlers element.ElementInvalid += new EventHandler(Element_ElementInvalid); //Draw the path if a line if (element is Line) { Line line = (Line)element; //If a connector and is not auto routed then calculate points if (element is Connector) { Connector connector = (Connector)element; if (connector.Points == null) { connector.CalculateRoute(); } } line.DrawPath(); } //Set any containers for child elements if (element is IPortContainer) { IPortContainer container = (IPortContainer)element; foreach (Port port in container.Ports.Values) { port.SetContainer(this); } } CreateRenderList(); OnElementInvalid(); //Raise the ElementInserted event OnElementInserted(element); }