//Dibuja el árbol public void DibujarArbol(Graphics grafo, Font fuente, Brush Relleno, Brush RellenoFuente, Pen Lapiz, int dato, Brush encuentro) { Pen blackPen = new Pen(Color.Black, 1); int x = 100; int y = 75; if (Raiz == null) { return; } //Posicion de todos los Nodos. Raiz.PosicionNodo(ref x, y); //Dibuja los Enlaces entre nodos. Raiz.DibujarRamas(grafo, blackPen); //Dibuja todos los Nodos. Raiz.DibujarNodo(grafo, fuente, Relleno, RellenoFuente, Lapiz, dato, encuentro); }
//Dibuja el nodo en la posición especificada. public void DibujarNodo(Graphics grafo, Font fuente, Brush Relleno, Brush RellenoFuente, Pen Lapiz, int dato, Brush encuentro) { Pen blackPen = new Pen(Color.Black, 1); //Dibuja el contorno del nodo. Rectangle rect = new Rectangle( (int)(CoordenadaX - Radio / 2), (int)(CoordenadaY - Radio / 2), Radio, Radio); if (valor == dato) { grafo.FillEllipse(encuentro, rect); } else { grafo.FillEllipse(encuentro, rect); grafo.FillEllipse(Relleno, rect); } grafo.DrawEllipse(blackPen, rect); //Dibuja el valor del nodo. StringFormat formato = new StringFormat(); formato.Alignment = StringAlignment.Center; formato.LineAlignment = StringAlignment.Center; grafo.DrawString(valor.ToString(), fuente, Brushes.Black, CoordenadaX, CoordenadaY, formato); //Dibuja los nodos hijos derecho e izquierdo. if (NodoIzquierdo != null) { NodoIzquierdo.DibujarNodo(grafo, fuente, Brushes.YellowGreen, RellenoFuente, Lapiz, dato, encuentro); } if (NodoDerecho != null) { NodoDerecho.DibujarNodo(grafo, fuente, Brushes.Yellow, RellenoFuente, Lapiz, dato, encuentro); } }