示例#1
0
        /// <summary>
        /// Final change to perform drawing.
        /// </summary>
        /// <param name="tc">Reference to owning TreeControl.</param>
        /// <param name="g">Reference to Graphics instance to draw into.</param>
        /// <param name="displayNodes">Collection of nodes in display.</param>
        public override void PostDrawNodes(TreeControl tc, Graphics g, ArrayList displayNodes)
        {
            // If we are trying to show an image box
            if (tc.GroupImageBox)
            {
                // Find total size covered by the root collection
                Rectangle rootBounds = tc.Nodes.Cache.Bounds;

                // Recover the actual control drawing area in node space
                Rectangle drawRect = tc.ClientToNodeSpace(tc.DrawRectangle);

                // If there is blank space at the bottom of the nodes
                if (rootBounds.Bottom < drawRect.Bottom)
                {
                    // Create rectangle for the undrawn area
                    Rectangle fillArea = new Rectangle(drawRect.Left,
                                                       rootBounds.Bottom,
                                                       drawRect.Width,
                                                       drawRect.Bottom - rootBounds.Bottom);

                    // If we have a border around the control
                    if (tc.BorderStyle != TreeBorderStyle.None)
                    {
                        // Reduce with to just the image column
                        fillArea.Width = tc.GroupImageBoxWidth;

                        // Fill area in image in image column color
                        g.FillRectangle(tc.GetCacheGroupImageBoxColumnBrush(), fillArea);

                        // Draw column separator line on right hand side
                        g.DrawLine(tc.GetCacheGroupImageBoxLinePen(), fillArea.Right, fillArea.Top,
                                   fillArea.Right, fillArea.Bottom);
                    }
                    else
                    {
                        // No border, so just fill entire area in image column color
                        g.FillRectangle(tc.GetCacheGroupImageBoxColumnBrush(), fillArea);
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Draw the NodeCollection instance.
        /// </summary>
        /// <param name="tc">Reference to owning TreeControl.</param>
        /// <param name="nc">Reference to NodeCollection instance.</param>
        /// <param name="g">Reference to Graphics instance to draw into.</param>
        /// <param name="clipRectangle">Clipping rectangle used when drawing.</param>
        /// <param name="preDraw">True when drawing before children and fales for drawing after.</param>
        public override void Draw(TreeControl tc,
                                  NodeCollection nc,
                                  Graphics g,
                                  Rectangle clipRectangle,
                                  bool preDraw)
        {
            // The real root never has anything to draw
            if (!IsRealRootCollection(tc, nc))
            {
                // Let base class do its stuff
                base.Draw(tc, nc, g, clipRectangle, preDraw);

                // Only draw the extra separating lines and image column after children are drawn
                if (!preDraw)
                {
                    // The root within each group might have something to do
                    if (IsRootCollection(tc, nc))
                    {
                        // Do we need to account for the image box column?
                        if (tc.GroupImageBox && tc.GroupImageBoxColumn)
                        {
                            // Recover the actual control drawing area in node space
                            Rectangle drawRect = tc.ClientToNodeSpace(tc.DrawRectangle);

                            // Get the bounding rectangle of the collection
                            Rectangle ncBounds = nc.Cache.Bounds;

                            // If this the first visible collection
                            bool firstVisibleCollection = (ncBounds.Top <= drawRect.Top) && (ncBounds.Bottom >= drawRect.Top);

                            // Adjust backwards to account for group indent
                            ncBounds.X -= tc.GroupIndentLeft;

                            // Adjust to just the image column width
                            ncBounds.Width = tc.GroupImageBoxWidth;

                            // Draw the image column color
                            g.FillRectangle(tc.GetCacheGroupImageBoxColumnBrush(), ncBounds);

                            // Draw the separator line on right hand side of column
                            g.DrawLine(tc.GetCacheGroupImageBoxLinePen(), ncBounds.Right, ncBounds.Top,
                                       ncBounds.Right, ncBounds.Bottom - 1);

                            // We draw top and bottom collection separators, if we have no border
                            if (tc.BorderStyle == TreeBorderStyle.None)
                            {
                                // Draw the separator line on right side of control
                                g.DrawLine(tc.GetCacheGroupImageBoxLinePen(), drawRect.Right - 1, ncBounds.Top,
                                           drawRect.Right - 1, ncBounds.Bottom - 1);

                                // The first collection drawn on the control...
                                if (firstVisibleCollection)
                                {
                                    // ...needs a top line separator
                                    g.DrawLine(tc.GetCacheGroupImageBoxLinePen(), ncBounds.Right, drawRect.Top,
                                               drawRect.Right - 1, drawRect.Top);
                                }

                                bool lastSibling = true;

                                // Then search siblings...
                                for (int i = nc.ParentNode.Index + 1; i < nc.ParentNode.ParentNodes.Count; i++)
                                {
                                    Node next = nc.ParentNode.ParentNodes[i];

                                    // For a node that is visible...
                                    if (next.Visible)
                                    {
                                        lastSibling = false;
                                        break;
                                    }
                                }

                                // If the last sibling, or collection runs off end of control
                                if (lastSibling || (ncBounds.Bottom > drawRect.Bottom))
                                {
                                    // Find the bottom line for drawing
                                    int bottom = ncBounds.Bottom - 1;

                                    // If we party run off end of the control the use end of control instead
                                    if (bottom >= drawRect.Bottom)
                                    {
                                        bottom = drawRect.Bottom - 1;
                                    }

                                    // ...then draw separator line at bottom of collection
                                    g.DrawLine(tc.GetCacheGroupImageBoxLinePen(), ncBounds.Right, bottom,
                                               drawRect.Right - 1, bottom);
                                }
                            }
                        }
                    }
                }
            }
        }