示例#1
0
        /// <summary>
        /// 与RemoveChildNodeTemp成对出现
        /// </summary>
        public int AddChildNodeTemp(int index, TreeNodePro node)
        {
            int result = index;

            ///先添加到节点中
            if (index == -1)
            {
                result = this.Nodes.Add(node);
            }
            else
            {
                this.Nodes.Insert(index, node);
            }

            return(result);
        }
示例#2
0
        /// <summary>
        /// 从Nodes集合移除指定Node。为使我们能在删除时做一些统一的处理,
        /// 所有的节点删除必须使用此方法,若派生类重写此方法,必须最终调用base.RemoveChildNode
        /// </summary>
        public virtual void RemoveChildNode(TreeNodePro node)
        {
            // lukan090319
            ///若是ElementNode,且不是链接节点,则删除ElementNode的容器中的缓存
            //if (node is ElementNode && node.NodeType != TreeNodeType.Link)
            //{
            //    ElementNode elementNode = (ElementNode)node;

            //    ///先删除其子节点
            //    while (node.Nodes.Count > 0)
            //    {
            //        this.RemoveChildNode((TreeNodePro)node.FirstNode);
            //    }

            //    ///若在收藏夹中,则先移出来
            //    if (elementNode.Element.IsFavorite)
            //    {
            //        Service.Sdsite.CurrentDocument.RemoveFavorite(elementNode.Element);
            //    }

            //    ///从ElementNode的容器中删除
            //    TreeView.RemoveElementNode(elementNode.Element.Id);

            //    ///关闭当前节点打开的Form
            //    Service.Workbench.CloseWorkDocumentWithoutSave(elementNode.Element.Id,
            //        Service.Workbench.GetWorkDocumentType(elementNode.Element));
            //}

            ///删除的节点需要去除其选择
            if (TreeView.SelectedNodes.Contains(node))
            {
                TreeView.SelectedNodes.Remove(node);
            }

            ((TreeNode)node).Remove();
        }
示例#3
0
        public virtual int AddChildNode(int index, TreeNodePro node)
        {
            int result = index;

            ///先添加到节点中
            if (index == -1)
            {
                result = this.Nodes.Add(node);
            }
            else
            {
                this.Nodes.Insert(index, node);
            }

            ///设置图标
            node.SelectedImageKey = node.ImageKey = node.FactImageKey;

            ///初始化节点状态
            TreeView.InitNode(node);

            ///检查文件是否正常...................

            return(result);
        }
示例#4
0
        /// <summary>
        /// 使上一次画的线无效
        /// </summary>
        void InvalidatePrevLine(bool isCancelSelected)
        {
            ///停止悬停导致展开的计时器
            _BranchNodeBerth.Stop();
            _BranchNodeBerth.Tag = null;

            ///取消临时选择
            if (isCancelSelected && _tempSelectNode != null)
            {
                this.SelectedNodes.Remove(_tempSelectNode);
                _tempSelectNode = null;
            }

            ///使上次的画线区域无效
            if (_isDragDrop && _CanOrder)
            {
                Invalidate(new Rectangle(_lineBeginPoint.X - InvalidateOffset, _lineBeginPoint.Y - InvalidateOffset,
                    _lineEndPoint.X + InvalidateOffset * 2, InvalidateOffset * 2));
            }
        }
示例#5
0
        /* 检查文件是否正常
        ///检查文件是否正常
        if (node is ElementNode)
        {
            ElementNode elementNode = (ElementNode)node;

            ///添加到TreeNode的dic容器里去
            if (TreeView.TreeMode == TreeMode.General && elementNode.NodeType != TreeNodeType.Link)
            {
                TreeView.SetElementNode(elementNode);
            }

            ///检查文件是否存在:不存在,则在图标上画一个感叹号
            if (!Utility.File.Exists(elementNode.Element.AbsoluteFilePath))
            {
                string signKey = Service.Draw.GetSignKey(node.FactImageKey, SignType.ExcalmatoryPoint);
                if (!this.TreeView.ImageList.Images.ContainsKey(signKey))
                {
                    ///若是资源文件节点,则先确定图标已经存在
                    if (elementNode is ResourceFileNode)
                    {
                        ResourceFileNode fileNode = (ResourceFileNode)elementNode;
                        fileNode.InsureIcon();
                    }

                    ///画标记
                    Image signImage = this.TreeView.ImageList.Images[node.FactImageKey];
                    Service.Draw.DrawSign(signImage, SignType.ExcalmatoryPoint);
                    this.TreeView.ImageList.Images.Add(signKey, signImage);
                }

                node.SelectedImageKey = node.ImageKey = signKey;

                if (elementNode.IsFolder)
                {
                    node.ToolTipText = "此文件夹不存在!";
                }
                else
                {
                    node.ToolTipText = "此文件不存在!";
                }
            }
            else
            {
                bool isHealthy = true;
                switch (elementNode.Element.DataType)
                {
                    ///检查非首页型模板是否有正文型页面片
                    case DataType.Tmplt:
                        {
                            TmpltSimpleExXmlElement tmpltEle = elementNode.Element as TmpltSimpleExXmlElement;
                            if (tmpltEle.TmpltType != TmpltType.Home && !tmpltEle.HasContentSnip)
                            {
                                isHealthy = false;
                                elementNode.ToolTipText = "此模板没有正文型页面片。属于不完整模板。\r\n请为此模板创建正文型页面片,否则关联到它的页面无法正常生成。";
                            }
                            break;
                        }
                    ///检查页面是否正确关联了模板
                    case DataType.Page:
                        {
                            PageSimpleExXmlElement pageEle = elementNode.Element as PageSimpleExXmlElement;
                            if (string.IsNullOrEmpty(pageEle.TmpltId))
                            {
                                isHealthy = false;
                                elementNode.ToolTipText = "此页面没有设置关联模板,属于不完整页面。\r\n请重新选择关联模板,否则将无法生成最终页面。";
                            }
                            else
                            {
                                TmpltSimpleExXmlElement tmpltEle = Service.Sdsite.CurrentDocument.GetTmpltElementById(pageEle.TmpltId);
                                if (tmpltEle == null ||
                                    !File.Exists(tmpltEle.AbsoluteFilePath))
                                {
                                    isHealthy = false;
                                    elementNode.ToolTipText = "此页面关联的模板未能找到,属于不完整页面。\r\n请重新选择关联模板,否则无法生成最终页面。";
                                }
                                else
                                {
                                    isHealthy = true;
                                    //ElementNode tmpltNode = TreeView.GetElementNode(tmpltEle.Id);
                                    //if (tmpltNode != null)
                                    //{
                                    //    elementNode.ToolTipText = "此页面完整,关联的模板是:" + tmpltNode.FullPath + "。\r\n可生成最终页面。";
                                    //}
                                }
                            }
                            break;
                        }
                }

                ///不健康节点,在图标上添加标记
                if (!isHealthy)
                {
                    string signKey = Service.Draw.GetSignKey(node.FactImageKey, SignType.QuestionPoint);
                    if (!this.TreeView.ImageList.Images.ContainsKey(signKey))
                    {
                        Image signImage = this.TreeView.ImageList.Images[node.FactImageKey];
                        Service.Draw.DrawSign(signImage, SignType.QuestionPoint);
                        this.TreeView.ImageList.Images.Add(signKey, signImage);
                    }

                    node.SelectedImageKey = node.ImageKey = signKey;
                }
            }
        }
        */
        /// <summary>
        /// 与RemoveChildNodeTemp成对出现
        /// </summary>
        public int AddChildNodeTemp(TreeNodePro node)
        {
            return AddChildNodeTemp(-1, node);
        }
示例#6
0
 public NodeEventArgs(TreeNodePro node)
 {
     this._treeNode = node;
 }
示例#7
0
        protected bool CanInto(TreeNodePro[] srcNodes, TreeNodePro targetNode)
        {
            foreach (TreeNodePro node in srcNodes)
            {
                ///任何一次返回false则整体返回false
                if (!CanInto(node, targetNode))
                {
                    return false;
                }
            }

            return true;
        }
示例#8
0
 /// <summary>
 /// 检查node节点是否是grandfatherNode节点的孙节点
 /// (只需是grandfatherNodes中任何一个节点的孙节点就返回true)
 /// (即node通过其Parent属性的迭代调用一定能找到grandfatherNode)
 /// </summary>
 public bool CheckNodeParent(TreeNodePro node, TreeNodePro[] grandfatherNodes)
 {
     foreach (TreeNodePro grandfatherNode in grandfatherNodes)
     {
         if (CheckNodeParent(node, grandfatherNode))
         {
             return true;
         }
     }
     return false;
 }
示例#9
0
        /// <summary>
        /// 通过此方法判定是否允许将srcNode放入targetNode节点,作为targetNode的子节点
        /// </summary>
        public virtual bool CanInto(TreeNodePro srcNode, TreeNodePro targetNode)
        {
            ///判断目标节点是枝节点
            if (!targetNode.IsBranch)
            {
                return false;
            }

            ///根据接收类型判定
            TreeNodeType acceptType = targetNode.AcceptDragDropType;
            TreeNodeType srcType = srcNode.NodeType;

            if (srcType == TreeNodeType.None || acceptType == TreeNodeType.None)
            {
                return false;
            }

            if ((acceptType & srcType) == 0)
            {
                return false;
            }

            return true;
        }
示例#10
0
        /// <summary>
        /// 从Nodes集合移除指定Node。为使我们能在删除时做一些统一的处理,
        /// 所有的节点删除必须使用此方法,若派生类重写此方法,必须最终调用base.RemoveChildNode
        /// </summary>
        public virtual void RemoveChildNode(TreeNodePro node)
        {
            // lukan090319
            ///若是ElementNode,且不是链接节点,则删除ElementNode的容器中的缓存
            //if (node is ElementNode && node.NodeType != TreeNodeType.Link)
            //{
            //    ElementNode elementNode = (ElementNode)node;

            //    ///先删除其子节点
            //    while (node.Nodes.Count > 0)
            //    {
            //        this.RemoveChildNode((TreeNodePro)node.FirstNode);
            //    }

            //    ///若在收藏夹中,则先移出来
            //    if (elementNode.Element.IsFavorite)
            //    {
            //        Service.Sdsite.CurrentDocument.RemoveFavorite(elementNode.Element);
            //    }

            //    ///从ElementNode的容器中删除
            //    TreeView.RemoveElementNode(elementNode.Element.Id);

            //    ///关闭当前节点打开的Form
            //    Service.Workbench.CloseWorkDocumentWithoutSave(elementNode.Element.Id,
            //        Service.Workbench.GetWorkDocumentType(elementNode.Element));
            //}

            ///删除的节点需要去除其选择
            if (TreeView.SelectedNodes.Contains(node))
            {
                TreeView.SelectedNodes.Remove(node);
            }

            ((TreeNode)node).Remove();
        }
示例#11
0
 /// <summary>
 /// 单选模式时的选择
 /// </summary>
 private void NoMultiSelectNode(TreeNodePro node)
 {
     this.CurrentNode = node;
 }
示例#12
0
        /* 检查文件是否正常
         * ///检查文件是否正常
         * if (node is ElementNode)
         * {
         *  ElementNode elementNode = (ElementNode)node;
         *
         *  ///添加到TreeNode的dic容器里去
         *  if (TreeView.TreeMode == TreeMode.General && elementNode.NodeType != TreeNodeType.Link)
         *  {
         *      TreeView.SetElementNode(elementNode);
         *  }
         *
         *  ///检查文件是否存在:不存在,则在图标上画一个感叹号
         *  if (!Utility.File.Exists(elementNode.Element.AbsoluteFilePath))
         *  {
         *      string signKey = Service.Draw.GetSignKey(node.FactImageKey, SignType.ExcalmatoryPoint);
         *      if (!this.TreeView.ImageList.Images.ContainsKey(signKey))
         *      {
         *          ///若是资源文件节点,则先确定图标已经存在
         *          if (elementNode is ResourceFileNode)
         *          {
         *              ResourceFileNode fileNode = (ResourceFileNode)elementNode;
         *              fileNode.InsureIcon();
         *          }
         *
         *          ///画标记
         *          Image signImage = this.TreeView.ImageList.Images[node.FactImageKey];
         *          Service.Draw.DrawSign(signImage, SignType.ExcalmatoryPoint);
         *          this.TreeView.ImageList.Images.Add(signKey, signImage);
         *      }
         *
         *      node.SelectedImageKey = node.ImageKey = signKey;
         *
         *      if (elementNode.IsFolder)
         *      {
         *          node.ToolTipText = "此文件夹不存在!";
         *      }
         *      else
         *      {
         *          node.ToolTipText = "此文件不存在!";
         *      }
         *  }
         *  else
         *  {
         *      bool isHealthy = true;
         *      switch (elementNode.Element.DataType)
         *      {
         *          ///检查非首页型模板是否有正文型页面片
         *          case DataType.Tmplt:
         *              {
         *                  TmpltSimpleExXmlElement tmpltEle = elementNode.Element as TmpltSimpleExXmlElement;
         *                  if (tmpltEle.TmpltType != TmpltType.Home && !tmpltEle.HasContentSnip)
         *                  {
         *                      isHealthy = false;
         *                      elementNode.ToolTipText = "此模板没有正文型页面片。属于不完整模板。\r\n请为此模板创建正文型页面片,否则关联到它的页面无法正常生成。";
         *                  }
         *                  break;
         *              }
         *          ///检查页面是否正确关联了模板
         *          case DataType.Page:
         *              {
         *                  PageSimpleExXmlElement pageEle = elementNode.Element as PageSimpleExXmlElement;
         *                  if (string.IsNullOrEmpty(pageEle.TmpltId))
         *                  {
         *                      isHealthy = false;
         *                      elementNode.ToolTipText = "此页面没有设置关联模板,属于不完整页面。\r\n请重新选择关联模板,否则将无法生成最终页面。";
         *                  }
         *                  else
         *                  {
         *                      TmpltSimpleExXmlElement tmpltEle = Service.Sdsite.CurrentDocument.GetTmpltElementById(pageEle.TmpltId);
         *                      if (tmpltEle == null ||
         *                          !File.Exists(tmpltEle.AbsoluteFilePath))
         *                      {
         *                          isHealthy = false;
         *                          elementNode.ToolTipText = "此页面关联的模板未能找到,属于不完整页面。\r\n请重新选择关联模板,否则无法生成最终页面。";
         *                      }
         *                      else
         *                      {
         *                          isHealthy = true;
         *                          //ElementNode tmpltNode = TreeView.GetElementNode(tmpltEle.Id);
         *                          //if (tmpltNode != null)
         *                          //{
         *                          //    elementNode.ToolTipText = "此页面完整,关联的模板是:" + tmpltNode.FullPath + "。\r\n可生成最终页面。";
         *                          //}
         *                      }
         *                  }
         *                  break;
         *              }
         *      }
         *
         *      ///不健康节点,在图标上添加标记
         *      if (!isHealthy)
         *      {
         *          string signKey = Service.Draw.GetSignKey(node.FactImageKey, SignType.QuestionPoint);
         *          if (!this.TreeView.ImageList.Images.ContainsKey(signKey))
         *          {
         *              Image signImage = this.TreeView.ImageList.Images[node.FactImageKey];
         *              Service.Draw.DrawSign(signImage, SignType.QuestionPoint);
         *              this.TreeView.ImageList.Images.Add(signKey, signImage);
         *          }
         *
         *          node.SelectedImageKey = node.ImageKey = signKey;
         *      }
         *  }
         * }
         */

        /// <summary>
        /// 与RemoveChildNodeTemp成对出现
        /// </summary>
        public int AddChildNodeTemp(TreeNodePro node)
        {
            return(AddChildNodeTemp(-1, node));
        }
 public DragDropResult(TreeNodePro[] dragdropNodes, TreeNodePro dropNode, DragDropResultType dropResultType)
 {
     _dragdropNodes = dragdropNodes;
     _dropPutNode = dropNode;
     _dropResultType = dropResultType;
 }
示例#14
0
 public DragDropResult(TreeNodePro[] dragdropNodes, TreeNodePro dropNode, DragDropResultType dropResultType)
 {
     _dragdropNodes  = dragdropNodes;
     _dropPutNode    = dropNode;
     _dropResultType = dropResultType;
 }
示例#15
0
 /// <summary>
 /// 临时删除,一般供移动时使用
 /// </summary>
 public void RemoveChildNodeTemp(TreeNodePro node)
 {
     ((TreeNode)node).Remove();
 }
示例#16
0
        /// <summary>   
        /// 复选   
        /// </summary>
        private void MultiSelectNode(TreeNodePro node, bool isRightDown)
        {
            ///若是Enabled==false,则不处理
            TreeNodePro baseNode = node as TreeNodePro;
            if (baseNode != null && !baseNode.Enabled)
            {
                return;
            }

            ///先检查是否已经被选
            if (SelectedNodes.Contains(node))
            {
                ///已被选择。则检查是否是右键按下
                if (!isRightDown)
                {
                    ///不是右键按下,那么从选择集合里删除
                    SelectedNodes.Remove(node);
                }
            }
            else
            {
                ///未被选择。添加到选择集合
                SelectedNodes.Add(node);

                ///设置_currentNode节点
                SetCurrentNode(node);
            }
        }
示例#17
0
 private void SetCurrentNode(TreeNodePro node)
 {
     _CurrentNode = node;
     SelectedNode = null;
     if (node != null && !SelectedNodes.Contains(node))
     {
         SelectedNodes.Add(node);
     }
 }
示例#18
0
 /// <summary>
 /// 判定指定节点是否在不排序的节点内(不排序则也表示不允许在里面拖拽)
 /// </summary>
 bool NodeIsInNoOrder(TreeNodePro node)
 {
     TreeNodePro parentNode = node;
     while (parentNode.Parent != null)
     {
         parentNode = parentNode.Parent;
         if (parentNode.IsGrandchildNoOrder)
         {
             return true;
         }
     }
     return false;
 }
示例#19
0
        /// <summary>
        /// 与RemoveChildNodeTemp成对出现
        /// </summary>
        public int AddChildNodeTemp(int index, TreeNodePro node)
        {
            int result = index;
            ///先添加到节点中
            if (index == -1)
            {
                result = this.Nodes.Add(node);
            }
            else
            {
                this.Nodes.Insert(index, node);
            }

            return result;
        }
示例#20
0
        /// <summary>
        /// 刷新拖拽过程中的状态(主要是画分隔符或选中节点)
        /// </summary>
        void RefreshDragState()
        {
            try
            {
                ///找到鼠标当前位置的TreeNode
                Point mousePosition = PointToClient(Control.MousePosition);
                TreeNodePro mouseNode = (TreeNodePro)this.GetNodeAt(mousePosition);

                ///鼠标当前位置没有TreeNode,那么认为在最后一个TreeNode之后
                if (mouseNode == null)
                {
                    InvalidatePrevLine(true);
                    return;
                }

                if (CanOrder)
                {
                    DragDropResultType dropType = GetDragDropResult();

                    ///根据鼠标位置是否到达边界,来判断是否需要滚动
                    if ((mousePosition.Y >= ClientRectangle.Bottom - ScrollOffset) && (mousePosition.Y <= ClientRectangle.Bottom))
                    {
                        InvalidatePrevLine(false);
                        User32.ScrollTreeViewLineDown(this);
                    }
                    else if ((mousePosition.Y >= ClientRectangle.Top) && (mousePosition.Y <= ClientRectangle.Top + ScrollOffset))
                    {
                        InvalidatePrevLine(false);
                        User32.ScrollTreeViewLineUp(this);
                    }
                    else
                    {
                        ///如果处于Into状态,则根据停放时间将其展开
                        if ((!mouseNode.IsExpanded) &&
                            dropType == DragDropResultType.Into && mouseNode.IsDockExpand)
                        {
                            if (_BranchNodeBerth.Tag != mouseNode)
                            {
                                _BranchNodeBerth.Stop();

                                _BranchNodeBerth.Tag = mouseNode;
                                _BranchNodeBerth.Start();
                            }
                        }

                        ///如果获取结果跟上次不一样,则重绘
                        if (mouseNode != _dropResultNode || dropType != _dropResultType
                            || (_tempSelectNode == null && dropType == DragDropResultType.Into))
                        {
                            //使鼠标附近的区域无效
                            InvalidatePrevLine(true);

                            ///如果这次是Into,则选择
                            if (dropType == DragDropResultType.Into)
                            {
                                _tempSelectNode = mouseNode;
                                SelectedNodes.Add(mouseNode);
                            }
                        }
                    }
                }
                else
                {
                    #region 不排序的情况

                    this.SelectedNode = mouseNode;

                    ///如果是枝节点,则根据停放时间将其展开
                    if ((!mouseNode.IsExpanded) && mouseNode.IsBranch)
                    {
                        if (_BranchNodeBerth.Tag != mouseNode)
                        {
                            _BranchNodeBerth.Stop();

                            _BranchNodeBerth.Tag = mouseNode;
                            _BranchNodeBerth.Start();
                        }
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#21
0
 /// <summary>
 /// 临时删除,一般供移动时使用
 /// </summary>
 public void RemoveChildNodeTemp(TreeNodePro node)
 {
     ((TreeNode)node).Remove();
 }
示例#22
0
        /// <summary>   
        /// 单选   
        /// </summary>
        private void SingleSelectNode(TreeNodePro node, bool isRightDown)
        {
            bool isSelectContained = SelectedNodes.Contains(node);

            ///若是右键,则先看是否在已经选择的节点上按下,若是,则基本不做处理
            if (isRightDown && isSelectContained)
            {
                ///设置_currentNode节点
                SetCurrentNode(node);
                return;
            }

            ///若是Enabled==false,则取消所有选择
            TreeNodePro baseNode = node as TreeNodePro;
            if (baseNode != null && !baseNode.Enabled)
            {
                ///清空
                SelectedNodes.Clear();
            }
            else
            {
                if (!isSelectContained)
                {
                    ///添加
                    SelectedNodes.Add(node);
                }

                ///清空其他
                SelectedNodes.Remove(node);
            }
        }
示例#23
0
        /// <summary>
        /// 此方法最终调用RemoveChildNode方法
        /// </summary>
        public void RemoveChildNodeAt(int index)
        {
            TreeNodePro node = (TreeNodePro)this.Nodes[index];

            RemoveChildNode(node);
        }
示例#24
0
        /// <summary>
        /// 检查node节点是否是grandfatherNode节点的孙节点
        /// (即node通过其Parent属性的迭代调用一定能找到grandfatherNode)
        /// </summary>
        /// <returns></returns>
        public bool CheckNodeParent(TreeNodePro node, TreeNodePro grandfatherNode)
        {
            ///若是node比grandfatherNode的Leve小,则肯定不是其孙节点
            if (node.Level <= grandfatherNode.Level)
            {
                return false;
            }

            TreeNodePro agentNode = node;
            do
            {
                agentNode = agentNode.Parent;
            }
            while (agentNode.Level != grandfatherNode.Level);

            return agentNode == grandfatherNode;
        }
示例#25
0
        /// <summary>
        /// 连选
        /// </summary>
        private void ContinueSelectNode(TreeNodePro node, bool isRightDown)
        {
            if (_CurrentNode == node)
            {
                SingleSelectNode(node, isRightDown);
                return;
            }

            ///找到这两个节点哪个是开头,哪个是结尾(即前后顺序)
            TreeNodePro topNode = (TreeNodePro)GetTopNode(_CurrentNode, node);
            TreeNodePro bottomNode = (node == topNode ? _CurrentNode : node);

            ///先清空
            SelectedNodes.Clear();
            //SelectedNodes.ClearWithout(_currentNode);

            TreeNodePro nextNode = topNode;
            while (nextNode != bottomNode)
            {
                SelectedNodes.Add(nextNode);
                nextNode = (TreeNodePro)nextNode.NextVisibleNode;
            }

            SelectedNodes.Add(bottomNode);
        }
示例#26
0
        public void InitNode(TreeNodePro node)
        {
            ///处理Enabled为false的情况
            TreeNodePro baseNode = node as TreeNodePro;
            if (baseNode != null && !baseNode.Enabled)
            {
                node.BackColor = BackColor;
                node.ForeColor = SystemColors.GrayText;
                return;
            }

            node.BackColor = BackColor;
            node.ForeColor = SystemColors.ControlText;
        }
示例#27
0
        private TreeNodePro GetTopNode(TreeNodePro node1, TreeNodePro node2)
        {
            Debug.Assert(node1.TreeView == node2.TreeView);

            ///先判断是否同一个对象
            if (object.ReferenceEquals(node1, node2))
            {
                return node1;
            }

            ///找到两个节点的较浅的深度值
            int minLevel = System.Math.Min(node1.Level, node2.Level);

            ///向上遍历,以其祖节点作为代理
            TreeNode agentNode1 = node1;
            while (agentNode1.Level != minLevel)
            {
                agentNode1 = agentNode1.Parent;
            }
            TreeNodePro agentNode2 = node2;
            while (agentNode2.Level != minLevel)
            {
                agentNode2 = agentNode2.Parent;
            }

            ///比较两个代理哪个大
            while (true)
            {
                ///在同一个父节点的情况下比较Index值
                if (agentNode1.Parent == agentNode2.Parent)
                {
                    int result = agentNode1.Index - agentNode2.Index;

                    ///为0则表示两个代理是同一个节点。这时哪个节点Level越小越靠前
                    if (result == 0)
                    {
                        return node1.Level < node2.Level ? node1 : node2;
                    }
                    else if (result > 0)
                    {
                        return node2;
                    }
                    else
                    {
                        return node1;
                    }
                }
                else
                {
                    agentNode1 = agentNode1.Parent;
                    agentNode2 = agentNode2.Parent;
                }
            }
        }
示例#28
0
        protected override void OnDragDrop(DragEventArgs drgevent)
        {
            try
            {
                //拖拽结束
                InvalidatePrevLine(true);

                ///获取拖拽结果
                _dropResultNode = (TreeNodePro)this.GetNodeAt(PointToClient(Control.MousePosition));

                ///鼠标当前位置没有TreeNode,那么认为在最后一个之后
                if (_dropResultNode == null)
                {
                    _dropResultNode = (TreeNodePro)this.Nodes[this.Nodes.Count - 1];
                }

                ///恢复一些辅助变量为初始化状态
                _isDragDrop = false;
                _beginPoint = Point.Empty;

                ///判断目标节点是否不是选择节点;或者不在选择节点的子节点内;
                ///
                ///注:(by zhucai)判断一个一个节点是否是另一节点的孙节点不能通过node.FullPath.StartWith的方式,
                ///因为可能出现上级节点名刚好等于当前节点祖节点的前面部分。
                if (Array.IndexOf(_dropNodes, _dropResultNode) == -1 && !CheckNodeParent(_dropResultNode, _dropNodes))
                {
                    //触发NodeDragDroping事件
                    DragDropNodeEventArgs ddn = new DragDropNodeEventArgs(drgevent, new DragDropResult(_dropNodes, _dropResultNode, GetDragDropResult()));

                    OnNodeDragDroping(ddn);

                    if (!ddn.Cancel)
                    {
                        /*
                        ///先从树里删除
                        _dropNode.Remove();

                        ///计算该插入的位置
                        int insertIndex = 0;
                        TreeNode parentNode = null;
                        switch (ddn.DragDropResult.DropType)
                        {
                            case DragDropResultType.Before:
                                parentNode = ddn.DragDropResult.DropPutNode.Parent;
                                insertIndex = ddn.DragDropResult.DropPutNode.Index;
                                break;
                            case DragDropResultType.After:
                                parentNode = ddn.DragDropResult.DropPutNode.Parent;
                                insertIndex = ddn.DragDropResult.DropPutNode.Index + 1;
                                break;
                            case DragDropResultType.Into:
                                parentNode = ddn.DragDropResult.DropPutNode;
                                insertIndex = parentNode.Nodes.Count;
                                break;
                            default:
                                Debug.Assert(false);
                                break;
                        }

                        ///插入树中
                        if (parentNode != null)
                        {
                            parentNode.Nodes.Insert(insertIndex, (BaseTreeNode)_dropNode);
                        }
                        else
                        {
                            this.Nodes.Insert(insertIndex, (BaseTreeNode)_dropNode);
                        }
                        */
                        ///触发NodeDragDroped事件
                        OnNodeDragDroped(ddn);
                    }
                }

                //this.SelectedNodes.AddRange(_dropNodes);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
            }

            base.OnDragDrop(drgevent);
        }
示例#29
0
        /// <summary>   
        /// 高亮显示节点   
        /// </summary>
        private void HighlightNode(TreeNodePro node)
        {
            ///处理Enabled为false的情况
            TreeNodePro baseNode = node as TreeNodePro;
            if (baseNode != null && !baseNode.Enabled)
            {
                node.BackColor = SystemColors.Highlight;
                node.ForeColor = SystemColors.GrayText;
                return;
            }

            node.BackColor = SystemColors.Highlight;
            node.ForeColor = SystemColors.HighlightText;
        }
示例#30
0
        protected override void OnPaint(PaintEventArgs e)
        {
            //如果其顺序有效,且在拖动,则在拖拽处画条横线,指示插入点
            if (CanOrder && _isDragDrop)
            {
                Point mousePosition = PointToClient(Control.MousePosition);
                TreeNodePro mouseNode = (TreeNodePro)this.GetNodeAt(mousePosition);
                bool mouseNodeIsNull = false;

                ///鼠标当前位置没有TreeNode,那么认为鼠标在最后一个TreeNode之后
                if (mouseNode == null)
                {
                    mouseNodeIsNull = true;
                    mouseNode = (TreeNodePro)this.Nodes[this.Nodes.Count - 1];
                }

                if (!mouseNodeIsNull)
                {
                    ///检测拖拽结果
                    DragDropResultType dropResultType = GetDragDropResult();

                    if (mouseNode != _dropResultNode || dropResultType != _dropResultType)
                    {
                        switch (dropResultType)
                        {
                            ///鼠标在目标节点之前
                            case DragDropResultType.Before:
                                {
                                    _lineBeginPoint = new Point(mouseNode.Bounds.X - 20, mouseNode.Bounds.Y);
                                    _lineEndPoint = new Point(mouseNode.Bounds.X + _InsertLineWidth, mouseNode.Bounds.Y);

                                    DrawInsertLine(e.Graphics, _lineBeginPoint.X, _lineBeginPoint.Y, CurrentNode.Bounds.Width);
                                    break;
                                }
                            ///鼠标在目标节点之后
                            case DragDropResultType.After:
                                {
                                    _lineBeginPoint = new Point(mouseNode.Bounds.X - 20, mouseNode.Bounds.Y + mouseNode.Bounds.Height);
                                    _lineEndPoint = new Point(mouseNode.Bounds.X + _InsertLineWidth, mouseNode.Bounds.Y + mouseNode.Bounds.Height);

                                    DrawInsertLine(e.Graphics, _lineBeginPoint.X, _lineBeginPoint.Y, CurrentNode.Bounds.Width);
                                    break;
                                }
                        }

                        ///只有在线画完后才将当前值存储起来
                        _dropResultType = dropResultType;
                        _dropResultNode = mouseNode;
                    }
                }
            }

            base.OnPaint(e);
        }
示例#31
0
        public virtual int AddChildNode(int index, TreeNodePro node)
        {
            int result = index;
            ///先添加到节点中
            if (index == -1)
            {
                result = this.Nodes.Add(node);
            }
            else
            {
                this.Nodes.Insert(index, node);
            }

            ///设置图标
            node.SelectedImageKey = node.ImageKey = node.FactImageKey;

            ///初始化节点状态
            TreeView.InitNode(node);

            ///检查文件是否正常...................

            return result;
        }