Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Tree view drawing problem

Tree view drawing problem

Scheduled Pinned Locked Moved C#
graphicsdata-structureshelp
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gwithey
    wrote on last edited by
    #1

    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 &lt; 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 &gt; 0 &amp;&amp; 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 &amp;&amp; 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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups