private void DrawGraphFirstTime() { // Bind graph to viewer engine viewer.Graph = graph; // Bind viewer engine to the panel GraphPanel.SuspendLayout(); viewer.Dock = System.Windows.Forms.DockStyle.Fill; GraphPanel.Controls.Add(viewer); GraphPanel.ResumeLayout(); }
private void SearchButton_Click(object sender, EventArgs e) { openFileDialog1.ShowDialog(); NamaFile.Text = openFileDialog1.FileName; string[] lines = System.IO.File.ReadAllLines(NamaFile.Text); a.nodes.Clear(); foreach (string line in lines) { string[] y = line.Split(" "); if (!a.contain(y[0])) { node temp = new node(y[0]); a.addNode(temp); if (!a.contain(y[1])) { node temp1 = new node(y[1]); a.addNode(temp1); temp.addAdj(temp1); } else { foreach (node i in a.nodes) { if (i.vertex == y[1]) { temp.addAdj(i); } } } } else { for (int i = 0; i < a.nodes.Count; i++) { if (a.nodes[i].vertex == y[0]) { if (!a.contain(y[1])) { node temp1 = new node(y[1]); a.addNode(temp1); a.nodes[i].addAdj(temp1); } else { foreach (node j in a.nodes) { if (j.vertex == y[1]) { a.nodes[i].addAdj(j); } } } } } } } richTextBox1.Text = File.ReadAllText(NamaFile.Text); Awal.Items.Clear(); Akhir.Items.Clear(); Awal.Items.Add("NONE"); Akhir.Items.Add("NONE"); Awal.Text = "NONE"; Akhir.Text = "NONE"; foreach (node i in a.nodes) { Awal.Items.Add(i.vertex); Akhir.Items.Add(i.vertex); } GraphPanel.Controls.Clear(); //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"); //create the graph content foreach (node i in a.nodes) { foreach (node j in a.nodes[a.searchIdxNode(i.vertex)].adjacent) { graph.AddEdge(i.vertex, j.vertex); } } //bind the graph to the viewer viewer.Graph = graph; //associate the viewer with the form GraphPanel.SuspendLayout(); viewer.Dock = System.Windows.Forms.DockStyle.Fill; GraphPanel.Controls.Add(viewer); GraphPanel.ResumeLayout(); //show the form GraphPanel.Show(); }