Example #1
0
        private void OnContentPanelPaint(object sender, PaintEventArgs e)
        {
            // Draw the nodes
            int x = HorizontalSpace;
            int y = VerticalSpace;
            int horizontalOffset = _expanderWidth + HorizontalSpace;

            if (_rootNodes.Count > 0)
            {
                Rectangle     treeBounds    = new Rectangle(0, 0, HorizontalSpace, VerticalSpace);
                SmartTreeNode current       = _rootNodes[0];
                Rectangle     smartTreeRect = RectangleToScreen(ClientRectangle);
                smartTreeRect = _contentPanel.RectangleToClient(smartTreeRect);

                while (current != null)
                {
                    current.SetTreeView(this);
                    Rectangle contentArea = CalculateContentArea(x, y, current.GetContentSize());
                    if (contentArea.IntersectsWith(smartTreeRect))
                    {
                        PaintNode(current, e.Graphics, x, y);
                    }
                    treeBounds = Rectangle.Union(treeBounds, contentArea);
                    y         += contentArea.Height + VerticalSpace;
                    if (current.IsExpanded &&
                        current.Nodes.Count > 0)
                    {
                        current = current.Nodes[0];
                        x      += horizontalOffset;
                    }
                    else if (current.NextNode != null)
                    {
                        current = current.NextNode;
                    }
                    else
                    {
                        current = current.Parent;
                        x      -= horizontalOffset;
                        while (current != null)
                        {
                            if (current.NextNode != null)
                            {
                                current = current.NextNode;
                                break;
                            }
                            else
                            {
                                current = current.Parent;
                                x      -= horizontalOffset;
                            }
                        }
                    }
                }
                _contentPanel.Size = new Size(treeBounds.Width + 2 * HorizontalSpace, treeBounds.Height + VerticalSpace);
            }
            else
            {
                _contentPanel.Size = Size;
            }
        }
Example #2
0
      private void PaintNode(SmartTreeNode theNode, Graphics g, int locationX, int locationY) {
         // Icon dimensions
         int imageMidpointX = locationX + _expanderWidth / 2;
         int imageMidpointY = locationY + (int) ( Font.SizeInPoints * 2 ) / 2;

         // Node dimensions
         Rectangle contentArea = CalculateContentArea(locationX, locationY, theNode.GetContentSize());
         int nodeHeight = contentArea.Height;
         int nodeBottom = locationY + nodeHeight;

         // Update node bounds
         theNode.Bounds = new Rectangle(locationX, locationY,
            _expanderWidth + HorizontalSpace + contentArea.Width,
            contentArea.Height);

         // Draw lines
         using( Pen pen = new Pen(LineColor) ) {
            pen.DashStyle = DashStyle;

            // Horizontal Line
            g.DrawLine(pen, imageMidpointX,
                       imageMidpointY,
                       contentArea.Left, imageMidpointY);

            Point verticalLineTop = new Point(imageMidpointX, imageMidpointY);
            Point verticalLineBottom = verticalLineTop;

            // Vertical line upwards
            if( theNode.Parent != null || theNode.PreviousNode != null ) {
               verticalLineTop = new Point(imageMidpointX, locationY - VerticalSpace);
            }

            // Vertical line downwards
            if( theNode.NextNode != null ) {
               verticalLineBottom = new Point(imageMidpointX, nodeBottom);
            }

            if( verticalLineTop != verticalLineBottom ) {
               g.DrawLine(pen, verticalLineTop, verticalLineBottom);
            }
         }

         // Draw plus and minus
         if( theNode.Nodes.Count > 0 ) {
            int imageLocationY = locationY + ( (int) ( Font.SizeInPoints * 2 ) - _expanderHeight ) / 2;
            if( theNode.IsExpanded ) {
               g.DrawImage(_expanderExpandedImage, locationX, imageLocationY);
            }
            else {
               g.DrawImage(_expanderCollapsedImage, locationX, imageLocationY);
            }
         }

         // draw the vertical dot line for the parent nodes if necessary
         using( Pen pen = new Pen(LineColor) ) {
            pen.DashStyle = DashStyle;
            SmartTreeNode parentNode = theNode.Parent;
            while( parentNode != null ) {
               if( parentNode.NextNode != null ) {
                  int parentImageLocationX = parentNode.Bounds.X + _expanderWidth/2;
                  g.DrawLine(pen, parentImageLocationX,
                             locationY - VerticalSpace,
                             parentImageLocationX,
                             locationY + nodeHeight);
               }
               parentNode = parentNode.Parent;
            }
         }

         // Draw checkbox:
         if(theNode.HasCheckBox) {
            int checkBoxLocationY = locationY + ( (int) ( Font.SizeInPoints * 2 ) - CheckBoxHeight ) / 2;
            if( theNode.Checked ) {
               CheckBoxRenderer.DrawCheckBox(g, new Point(contentArea.Left, checkBoxLocationY), CheckBoxState.CheckedNormal);
            }
            else {
               CheckBoxRenderer.DrawCheckBox(g, new Point(contentArea.Left, checkBoxLocationY), CheckBoxState.UncheckedNormal);
            }
            // Update text area to account for the space needed by the checkbox:
            contentArea = new Rectangle(contentArea.Left + CheckBoxWidth, contentArea.Top, contentArea.Width, contentArea.Height);
         }

         theNode.DrawContent(g, contentArea);
      }
Example #3
0
        private void PaintNode(SmartTreeNode theNode, Graphics g, int locationX, int locationY)
        {
            // Icon dimensions
            int imageMidpointX = locationX + _expanderWidth / 2;
            int imageMidpointY = locationY + (int)(Font.SizeInPoints * 2) / 2;

            // Node dimensions
            Rectangle contentArea = CalculateContentArea(locationX, locationY, theNode.GetContentSize());
            int       nodeHeight  = contentArea.Height;
            int       nodeBottom  = locationY + nodeHeight;

            // Update node bounds
            theNode.Bounds = new Rectangle(locationX, locationY,
                                           _expanderWidth + HorizontalSpace + contentArea.Width,
                                           contentArea.Height);

            // Draw lines
            using (Pen pen = new Pen(LineColor)) {
                pen.DashStyle = DashStyle;

                // Horizontal Line
                g.DrawLine(pen, imageMidpointX,
                           imageMidpointY,
                           contentArea.Left, imageMidpointY);

                Point verticalLineTop    = new Point(imageMidpointX, imageMidpointY);
                Point verticalLineBottom = verticalLineTop;

                // Vertical line upwards
                if (theNode.Parent != null || theNode.PreviousNode != null)
                {
                    verticalLineTop = new Point(imageMidpointX, locationY - VerticalSpace);
                }

                // Vertical line downwards
                if (theNode.NextNode != null)
                {
                    verticalLineBottom = new Point(imageMidpointX, nodeBottom);
                }

                if (verticalLineTop != verticalLineBottom)
                {
                    g.DrawLine(pen, verticalLineTop, verticalLineBottom);
                }
            }

            // Draw plus and minus
            if (theNode.Nodes.Count > 0)
            {
                int imageLocationY = locationY + ((int)(Font.SizeInPoints * 2) - _expanderHeight) / 2;
                if (theNode.IsExpanded)
                {
                    g.DrawImage(_expanderExpandedImage, locationX, imageLocationY);
                }
                else
                {
                    g.DrawImage(_expanderCollapsedImage, locationX, imageLocationY);
                }
            }

            // draw the vertical dot line for the parent nodes if necessary
            using (Pen pen = new Pen(LineColor)) {
                pen.DashStyle = DashStyle;
                SmartTreeNode parentNode = theNode.Parent;
                while (parentNode != null)
                {
                    if (parentNode.NextNode != null)
                    {
                        int parentImageLocationX = parentNode.Bounds.X + _expanderWidth / 2;
                        g.DrawLine(pen, parentImageLocationX,
                                   locationY - VerticalSpace,
                                   parentImageLocationX,
                                   locationY + nodeHeight);
                    }
                    parentNode = parentNode.Parent;
                }
            }

            // Draw checkbox:
            if (theNode.HasCheckBox)
            {
                int checkBoxLocationY = locationY + ((int)(Font.SizeInPoints * 2) - CheckBoxHeight) / 2;
                if (theNode.Checked)
                {
                    CheckBoxRenderer.DrawCheckBox(g, new Point(contentArea.Left, checkBoxLocationY), CheckBoxState.CheckedNormal);
                }
                else
                {
                    CheckBoxRenderer.DrawCheckBox(g, new Point(contentArea.Left, checkBoxLocationY), CheckBoxState.UncheckedNormal);
                }
                // Update text area to account for the space needed by the checkbox:
                contentArea = new Rectangle(contentArea.Left + CheckBoxWidth, contentArea.Top, contentArea.Width, contentArea.Height);
            }

            theNode.DrawContent(g, contentArea);
        }