protected void NDrawingView1_AsyncClick(object sender, EventArgs e)
        {
            NCallbackMouseEventArgs args = e as NCallbackMouseEventArgs;

            NNodeList            nodes  = NDrawingView1.HitTest(args);
            NNodeList            shapes = nodes.Filter(Nevron.Diagram.Filters.NFilters.Shape2D);
            NExpandCollapseCheck check  = null;
            int length = shapes.Count;

            for (int i = 0; i < length; i++)
            {
                if (shapes[i] is NExpandCollapseCheck)
                {
                    check = shapes[i] as NExpandCollapseCheck;
                    break;
                }
            }
            if (check == null)
            {
                return;
            }

            NExpandableShape shape = check.ParentNode.ParentNode as NExpandableShape;

            shape.Expand(!shape.Expanded);
        }
        protected NExpandableShape CreateVertex(string text)
        {
            NExpandableShape vertex = new NExpandableShape();

            vertex.Text = text;
            NDrawingView1.Document.ActiveLayer.AddChild(vertex);
            return(vertex);
        }
        protected void ConnectShapes(NExpandableShape fromShape, NExpandableShape toShape)
        {
            NLineShape connector = new NLineShape();

            connector.StyleSheetName = NDR.NameConnectorsStyleSheet;

            NDrawingView1.Document.ActiveLayer.AddChild(connector);
            connector.FromShape = fromShape;
            connector.ToShape   = toShape;
        }
            /// <summary>
            ///
            /// </summary>
            /// <param name="expandShape"></param>
            public void Expand(bool expandShape)
            {
                // expand or collapse in a single transation
                StartTransaction(expandShape ? "Expand Tree" : "Collapse Tree");

                // mark shape as expanded
                Expanded = expandShape;

                // show/hide the plus or minus
                NExpandCollapseCheck check = GetExpandCollapseCheck();

                NPathPrimitive pathPrimitive;

                pathPrimitive         = check.Primitives.GetChildAt(1) as NPathPrimitive;
                pathPrimitive.Visible = !expandShape;

                pathPrimitive         = check.Primitives.GetChildAt(2) as NPathPrimitive;
                pathPrimitive.Visible = expandShape;

                // show/hide all outgoing shapes
                NNodeList nodes = GetOutgoingShapes();

                for (int i = 0; i < nodes.Count; i++)
                {
                    NShape shape = (nodes[i] as NShape);
                    shape.Visible = expandShape;
                }

                // show/hide all destination shapes
                nodes = GetDestinationShapes();
                for (int i = 0; i < nodes.Count; i++)
                {
                    NShape shape = (nodes[i] as NShape);
                    shape.Visible = expandShape;
                }

                // expand/collapse the destination shapes
                for (int i = 0; i < nodes.Count; i++)
                {
                    NExpandableShape expandableShape = (nodes[i] as NExpandableShape);
                    if (expandableShape != null)
                    {
                        expandableShape.Expand(expandShape);
                    }
                }

                // commit the transaction
                Commit();
            }
        protected void InitDocument()
        {
            NDrawingView1.Document.GraphicsSettings.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
            NDrawingView1.Document.GraphicsSettings.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
            NDrawingView1.Document.GraphicsSettings.PixelOffsetMode   = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;

            // set up visual formatting
            NDrawingView1.Document.Style.FillStyle = new NColorFillStyle(Color.Linen);

            NDrawingView1.Document.BackgroundStyle.FrameStyle.Visible = false;

            // all shapes will have shadow dropped below document content
            NDrawingView1.Document.Style.ShadowStyle.Type       = ShadowType.GaussianBlur;
            NDrawingView1.Document.Style.ShadowStyle.Offset     = new NPointL(5, 5);
            NDrawingView1.Document.Style.ShadowStyle.FadeLength = new NLength(5);
            NDrawingView1.Document.ShadowsZOrder = ShadowsZOrder.BehindDocument;

            // root
            NExpandableShape company = CreateVertex("The Company");

            // products branch
            NExpandableShape products = CreateVertex("Products and Services");

            ConnectShapes(company, products);

            NExpandableShape product1 = this.CreateVertex("Product1");

            ConnectShapes(products, product1);

            NExpandableShape product2 = this.CreateVertex("Product2");

            ConnectShapes(products, product2);

            // how to reach
            NExpandableShape reach = CreateVertex("How to reach");

            ConnectShapes(company, reach);

            NExpandableShape phone = this.CreateVertex("Phone");

            ConnectShapes(reach, phone);

            NExpandableShape fax = this.CreateVertex("Fax");

            ConnectShapes(reach, fax);

            NExpandableShape website = this.CreateVertex("Website");

            ConnectShapes(reach, website);

            // research
            NExpandableShape research = CreateVertex("Research");

            ConnectShapes(company, research);

            NExpandableShape tech = this.CreateVertex("Techinical");

            ConnectShapes(research, tech);

            NExpandableShape marketing = this.CreateVertex("Marketing");

            ConnectShapes(research, marketing);

            NExpandableShape newTech = this.CreateVertex("New Tech");

            ConnectShapes(research, newTech);

            NNodeList nodes = new NNodeList();

            nodes.Add(company);

            // create a layout context
            NLayoutContext layoutContext = new NLayoutContext();

            layoutContext.BodyAdapter          = new NShapeBodyAdapter(NDrawingView1.Document);
            layoutContext.BodyContainerAdapter = new NDrawingBodyContainerAdapter(NDrawingView1.Document);
            layoutContext.GraphAdapter         = new NShapeGraphAdapter();

            // first apply a layered tree layout
            // to set a start position of the shapes as a simple tree
            NTreeLayout treeLayout = new NLayeredTreeLayout();

            treeLayout.Layout(nodes, layoutContext);

            // then apply a symmetrical layout to layout them in a ring fasion
            NSymmetricalLayout symmetricalLayout = new NSymmetricalLayout();

            symmetricalLayout.DesiredDistanceForce.DesiredDistance = 100;
            symmetricalLayout.Layout(nodes, layoutContext);

            // size the document to the content (note that we use irregular margins)
            NDrawingView1.Document.SizeToContent(new NSizeF(100, 100), new Nevron.Diagram.NMargins(20, 20, 100, 20));

            // add title spanning the entire document width
            NTextShape text = new NTextShape("Company Structure", new NRectangleF(5, -50, NDrawingView1.Document.Width - 5, 50));

            text.Style.TextStyle = new NTextStyle(new Font("Times New Roman", 23, FontStyle.Bold));
            text.Style.TextStyle.StringFormatStyle.HorzAlign = HorzAlign.Center;
            NDrawingView1.Document.ActiveLayer.AddChild(text);
        }