Example #1
0
        // MEnggambar graf di salah satu grid
        private void LoadGrid(List <List <String> > graphdetails)
        {
            // Create the interop host control.
            System.Windows.Forms.Integration.WindowsFormsHost host =
                new System.Windows.Forms.Integration.WindowsFormsHost();

            // create a form
            System.Windows.Forms.MaskedTextBox form = new System.Windows.Forms.MaskedTextBox();
            //create a viewer object
            Microsoft.Msagl.GraphViewerGdi.GViewer viewer = new Microsoft.Msagl.GraphViewerGdi.GViewer();
            //create a graph object
            Microsoft.Msagl.Drawing.Graph graph = new Microsoft.Msagl.Drawing.Graph("Graph Drawing");
            //create the graph content

            foreach (List <string> L in graphdetails)
            {
                graph.AddNode(L[0]);
                for (int i = 1; i < L.Count; i++)
                {
                    graph.AddEdge(L[i], L[0]).Attr.ArrowheadAtTarget = Microsoft.Msagl.Drawing.ArrowStyle.None;
                }
            }
            foreach (var node in graph.Nodes)
            {
                node.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Circle;
            }

            //bind the graph to the viewer
            viewer.Graph = graph;
            form.SuspendLayout();
            viewer.Dock = System.Windows.Forms.DockStyle.Fill;
            form.Controls.Add(viewer);
            form.ResumeLayout();

            // Assign the MaskedTextBox control as the host control's child.
            host.Child = form;

            // Add the interop host control to the Grid
            // control's collection of child controls.
            this.grid2.Children.Add(host);
        }