Exemplo n.º 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();
                    }
                }
            }
        }
Exemplo n.º 2
0
        // Collapse the children recursively but don't redraw.
        private void CollapseInternal()
        {
            bool selected = false;

            // Recursively collapse, if a child was selected, mark to select the parent.
            if (childCount > 0)
            {
                for (int i = 0; i < childCount; i++)
                {
                    if (null != treeView)
                    {
                        if (treeView.SelectedNode == children[i])
                        {
                            selected = true;
                        }
                    }
                    children[i].CollapseInternal();
                }
            }
            if (expanded)
            {
                // Do the events.
                TreeViewCancelEventArgs eventArgs = new TreeViewCancelEventArgs(this, false, TreeViewAction.Collapse);
                if (null != treeView)
                {
                    treeView.OnBeforeCollapse(eventArgs);
                }
                if (!eventArgs.Cancel)
                {
                    // The node is now collapsed.
                    expanded = false;
                    if (null != treeView)
                    {
                        treeView.OnAfterCollapse(new TreeViewEventArgs(this));
                    }
                }
            }
            if (selected)
            {
                if (null != treeView)
                {
                    treeView.SelectedNode = this;
                }
            }
        }
Exemplo n.º 3
0
 /// <include file='doc\TreeNode.uex' path='docs/doc[@for="TreeNode.DoCollapse"]/*' />
 /// <devdoc>
 ///     Windows TreeView doesn't send the proper notifications on collapse, so we do it manually.
 /// </devdoc>
 private void DoCollapse(TreeView tv) {
     if ((State & NativeMethods.TVIS_EXPANDED) != 0) {
         TreeViewCancelEventArgs e = new TreeViewCancelEventArgs(this, false, TreeViewAction.Collapse);
         tv.OnBeforeCollapse(e);
         if (!e.Cancel) {
             UnsafeNativeMethods.SendMessage(new HandleRef(tv, tv.Handle), NativeMethods.TVM_EXPAND, NativeMethods.TVE_COLLAPSE, Handle);
             tv.OnAfterCollapse(new TreeViewEventArgs(this));
         }
     }
 }