private void nuevoToolStripMenuItem_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e) { nuevoToolStripMenuItem.HideDropDown(); switch (e.ClickedItem.Name) { case "Nuevo": band = false; mov = false; BackColor = Color.White; g.Clear(BackColor); AristaNoDirigida.Enabled = true; AristaDirigida.Enabled = true; g2 = new Grafo(); grafo = new Grafo(); nombre = 'A'; gactivo = false; break; case "Abrir": OpenFileDialog filed = new OpenFileDialog(); filed.InitialDirectory = Application.StartupPath + "\\Ejemplos"; filed.DefaultExt = ".grafo"; string namefile; filed.Filter = "Grafo Files (*.grafo)|*.grafo|All files (*.*)|*.*"; if (filed.ShowDialog() == DialogResult.OK) { namefile = filed.FileName; try { using (Stream stream = File.Open(namefile, FileMode.Open)) { BinaryFormatter bin = new BinaryFormatter(); grafo = (Grafo)bin.Deserialize(stream); grafo.pinta(g); } } catch (IOException exe) { MessageBox.Show(exe.ToString()); } g2 = new Grafo(); accion = 1; grafo.desseleccionar(); nombre = 'A'; for (int nn = 0; nn < grafo.Count; nn++) { nombre++; } } break; case "Guardar": SaveFileDialog sav = new SaveFileDialog(); sav.Filter = "Grafo Files (*.grafo)|*.grafo|All files (*.*)|*.*"; sav.InitialDirectory = Application.StartupPath + "\\ProyectosGrafo"; String nombr; if (sav.ShowDialog() == DialogResult.OK) { nombr = sav.FileName; try { using (Stream stream = File.Open(nombr, FileMode.Create)) { BinaryFormatter bin = new BinaryFormatter(); bin.Serialize(stream, grafo); } } catch (IOException exe) { MessageBox.Show(exe.ToString()); } } break; case "BorraGrafo": grafo = new Grafo(); g.Clear(BackColor); g2 = new Grafo(); nombre = 'A'; break; case "Salir": System.Windows.Forms.Application.Exit(); break; } }
private void Form1_MouseUp(object sender, MouseEventArgs e) { NodoP des; Graphics au; au = Graphics.FromImage(bmp1); au.Clear(BackColor); switch (accion) { case 1: p = pm; pm = e.Location; band = true; Form1_Paint(this, null); band = false; break; case 2: nu = null; break; case 3: des = (NodoP)grafo.Find(delegate(NodoP a) { if (e.Location.X > a.POS.X - 15 && e.Location.X < a.POS.X + 30 && e.Location.Y > a.POS.Y - 15 && e.Location.Y < a.POS.Y + 30) { return(true); } else { return(false); } }); if (des != null && nu != null) { if (nu.insertaRelacion(des, grafo.Aristas.Count)) { a = new Arista(tipoarista, nu, des, "e" + grafo.Aristas.Count.ToString()); grafo.AgregaArista(a); nu.GRADO++; des.GRADO++; nu.GradoExterno++; des.GradoInterno++; } if (tipoarista == 2 && a.Destino.NOMBRE != a.Origen.NOMBRE) { des.insertaRelacion(nu, grafo.Aristas.Count - 1); des.GradoExterno++; nu.GradoInterno++; } grafo.pinta(au); band = false; nu = null; } else { grafo.pinta(au); } g.DrawImage(bmp1, 0, 0); break; case 4: nu = (NodoP)grafo.Find(delegate(NodoP a) { if (e.Location.X > a.POS.X - 15 && e.Location.X < a.POS.X + 30 && e.Location.Y > a.POS.Y - 15 && e.Location.Y < a.POS.Y + 30) { return(true); } else { return(false); } }); if (nu != null) { grafo.RemueveNodo(nu); band = true; if (grafo.Count == 0) { nombre = 'A'; gactivo = false; } Form1_Paint(this, null); band = false; } break; case 7: case 9: case 8: SeleccionaNodos(); break; } }