Tree view drawing problem
C#
1
Posts
1
Posters
0
Views
1
Watching
-
Hi i am trying to write a tree view control however have come accross difficulty in drawing the vertical lines. The bellow method currently works by fining the cumulative height of the last branch it was in and then calls AmountToDeduct(nodes[i].Nodes) to reduce this to the correct height for the next line. However this is very slow. Does anyone know a way i can simply not add nodeheight to the newLineFinishPoint if it is not needed apposed to taking away from the total heigh.
private Point PositionNodes(List<Node> nodes, Point point)
{
// Create new start point for downwards line
Point newStartPoint = new Point();
Point newFinishPoint = new Point();
newStartPoint = point;int nodeHeight = nodes\[0\].Size.Height; // Loop nodes for(int i = 0; i < nodes.Count; i++) { // Set node location and draw nodes\[i\].Location = point; // Increase Y by one line point.Y += nodeHeight; // If node has child nodes if (nodes\[i\].Nodes.Count > 0 && nodes\[i\].Expanded) { // Call method again on child nodes point.Y = PositionNodes(nodes\[i\].Nodes, new Point(point.X + m\_xIndentation, point.Y)).Y; } // Set finishing point of line newFinishPoint = point; newFinishPoint.Y -= (int)(nodes\[0\].Size.Height \* 0.5); // If node has only one child and is expanded reduce line by this amount if (nodes.Count == 1 && nodes\[i\].Expanded) { // Reduce line by child nodes amount newFinishPoint.Y -= AmountToDeduct(nodes\[i\].Nodes); } // Add points to list m\_linePoints.Add(newStartPoint); m\_linePoints.Add(newFinishPoint); } // Cumulative height of nodes return point; }
Thanks in advance