给treelist控件添加右键菜单

         /// <summary>
        /// 增加右键菜单
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeList1_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Right)
            {
                return;
            }
            TreeList tree = sender as TreeList;
            TreeListHitInfo hitInfo = tree.CalcHitInfo(e.Location);


            if (hitInfo.HitInfoType != HitInfoType.Cell)
            {
                return;
            }

            tree.Focus();
            if (hitInfo.Node != null)
            {
                tree.FocusedNode = hitInfo.Node;
            }
            popupMenu1.ShowPopup(tree.PointToScreen(e.Location));           
        }

你可能感兴趣的:(给treelist控件添加右键菜单)