Exemple #1
0
        private void CollapseInternal(bool byInternal)
        {
            if (!is_expanded || nodes.Count < 1)
            {
                return;
            }

            if (IsRoot)
            {
                return;
            }

            bool     cancel    = false;
            TreeView tree_view = TreeView;

            if (tree_view != null)
            {
                TreeViewCancelEventArgs e = new TreeViewCancelEventArgs(this, false, TreeViewAction.Collapse);
                tree_view.OnBeforeCollapse(e);
                cancel = e.Cancel;
            }

            if (!cancel)
            {
                int count_to_next = CountToNext();

                is_expanded = false;

                if (tree_view != null)
                {
                    tree_view.OnAfterCollapse(new TreeViewEventArgs(this));

                    bool hbar_visible = tree_view.hbar.Visible;
                    bool vbar_visible = tree_view.vbar.Visible;

                    tree_view.RecalculateVisibleOrder(this);
                    tree_view.UpdateScrollBars(false);

                    // CollapseBelow if we affect the visible area
                    if (visible_order < tree_view.skipped_nodes + tree_view.VisibleCount + 1 && ArePreviousNodesExpanded)
                    {
                        tree_view.CollapseBelow(this, count_to_next);
                    }
                    if (!byInternal && HasFocusInChildren())
                    {
                        tree_view.SelectedNode = this;
                    }

                    // If one or both of our scrollbars disappeared,
                    // invalidate everything
                    if ((hbar_visible & !tree_view.hbar.Visible) || (vbar_visible & !tree_view.vbar.Visible))
                    {
                        tree_view.Invalidate();
                    }
                }
            }
        }