当前位置:编程学习 > C#/ASP.NET >>

江湖救急,客户需要,树图操作

实现效果要求:
1、 采用vs2010,C#语言。
2、 采用TreeView实现树形菜单,当鼠标右键单击某个结点时并且按下Ctrl键,鼠标形状变为小手,上下移动鼠标可以将树形结点进行排序,当释放Ctrl键和鼠标后,鼠标形状回复默认图标,树形菜单可以显示出排序后的菜单。

请问,各位大侠可不可以给小弟点指点,说说思路。如果有点代码示例就更好了。

时间挺紧,谢谢各位了,100分献上。 --------------------编程问答-------------------- 1.给你的Node节点绑定onmousedown事件,定义一个全局变量,默认为0,在事件里面判断是否是右键,是右键的话,将变量置为1,给你的Node再绑定onmouseup事件,里面将那个全局变量置为初始值0.

2.给document加上一个onkeydown事件,先判断第一步定义的全局变量是否等于1,如果不是,就直接return,然后再判断按下的键值,如果是Ctrl+40(下)话,通过这个node得到父node,通过父node得到当前node的下一个node,然后把两个node进行替换操作(怎么替换不用说了吧),如果是Ctrl+38(上)话,跟上的操作,相反就行了,如果要异步保存的话,当两个node替换后,通过ajax对数据库中的这两个值的排序号按照新的保存一下就行了。

这是我的思路,仅供参考,希望能帮助到你。 --------------------编程问答--------------------
引用 1 楼 sh524555685 的回复:
1.给你的Node节点绑定onmousedown事件,定义一个全局变量,默认为0,在事件里面判断是否是右键,是右键的话,将变量置为1,给你的Node再绑定onmouseup事件,里面将那个全局变量置为初始值0.

2.给document加上一个onkeydown事件,先判断第一步定义的全局变量是否等于1,如果不是,就直接return,然后再判断按下的键值,如果是Ctrl+40(下)话,通过这……


谢谢您的思路小弟明白了。
问题一:能详细说一下,怎么给"Node"绑定“onmousedown”事件吗?
是不是给“TreeView”绑定“onmousedown”事件啊,使用“NodeMouseClick”事件可以吗?

问题二:怎样判断“右键”呢?

问题三:怎样获取“按键”的值,并判断“Ctrl+40(下)”或是“Ctrl+40(下)”上???
--------------------编程问答-------------------- 问题一:给treeview加鼠标事件 参考
问题二:判断右键
问题三:取按下键盘键值 --------------------编程问答-------------------- mark --------------------编程问答-------------------- 鼠标移上去是默认的鼠标,没有像你说的变成了等待
cursor这个属性你试试看LZ --------------------编程问答--------------------

一个鼠标左右键控制的问题,在控件的MouseDown事件中: 
private   void   panelClose_MouseDown(object   sender,   System.Windows.Forms.MouseEventArgs   e) 

if(   e.Button   =   MouseButtons.Right) 

//   按右键执行的操作 

else 

//   按左键执行的操作 



--------------------编程问答-------------------- 你用了它能省掉90%的工作了

http://www.flexibletreeview.com/ --------------------编程问答-------------------- 百度

JS 树型菜单 --------------------编程问答-------------------- 看MSDN

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //设置属性
            treeView1.AllowDrop = true;
            treeView1.Dock = DockStyle.Fill;
            


            this.treeView1.Nodes.AddRange(new TreeNode[] {
            new TreeNode("IT技术", new TreeNode[] {
            new TreeNode(".Net", new TreeNode[] {
            new TreeNode("Silverlight"), new TreeNode("ASP.NET"),new TreeNode("Winform")}),
            new TreeNode("Java技术", new TreeNode[] {new TreeNode("Java EE"),
            new TreeNode("Java SE"), new TreeNode("Java ME")}),
            new TreeNode("其它技术", new TreeNode[] {
            new TreeNode("Web开发", new TreeNode[] {new TreeNode("ASP"),
            new TreeNode("PHP", new TreeNode[] {new TreeNode("AJAX"),new TreeNode("JS")})}),
            new TreeNode("数据库"),new TreeNode("移动设备")})})});

            treeView1.ExpandAll();

        }

        private void treeView1_ItemDrag(object sender, ItemDragEventArgs e)
        {
            // Move the dragged node when the left mouse button is used.
            if (e.Button == MouseButtons.Left)
            {
                DoDragDrop(e.Item, DragDropEffects.Move);
            }

            // Copy the dragged node when the right mouse button is used.
            else if (e.Button == MouseButtons.Right)
            {
                DoDragDrop(e.Item, DragDropEffects.Copy);
            }
        }

        private void treeView1_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = e.AllowedEffect;
        }

        private void treeView1_DragOver(object sender, DragEventArgs e)
        {
            // Retrieve the client coordinates of the mouse position.
            Point targetPoint = treeView1.PointToClient(new Point(e.X, e.Y));

            // Select the node at the mouse position.
            treeView1.SelectedNode = treeView1.GetNodeAt(targetPoint);
        }

        private void treeView1_DragDrop(object sender, DragEventArgs e)
        {
            // Retrieve the client coordinates of the drop location.
            Point targetPoint = treeView1.PointToClient(new Point(e.X, e.Y));

            // Retrieve the node at the drop location.
            TreeNode targetNode = treeView1.GetNodeAt(targetPoint);

            // Retrieve the node that was dragged.
            TreeNode draggedNode = (TreeNode)e.Data.GetData(typeof(TreeNode));

            // Confirm that the node at the drop location is not 
            // the dragged node or a descendant of the dragged node.
            if (!draggedNode.Equals(targetNode) && !ContainsNode(draggedNode, targetNode))
            {
                // If it is a move operation, remove the node from its current 
                // location and add it to the node at the drop location.
                if (e.Effect == DragDropEffects.Move)
                {
                    draggedNode.Remove();
                    targetNode.Nodes.Add(draggedNode);
                }

                // If it is a copy operation, clone the dragged node 
                // and add it to the node at the drop location.
                else if (e.Effect == DragDropEffects.Copy)
                {
                    targetNode.Nodes.Add((TreeNode)draggedNode.Clone());
                }

                // Expand the node at the location 
                // to show the dropped node.
                targetNode.Expand();
            }
        }


        // Determine whether one node is a parent 
        // or ancestor of a second node.
        private bool ContainsNode(TreeNode node1, TreeNode node2)
        {
            // Check the parent node of the second node.
            if (node2.Parent == null) return false;
            if (node2.Parent.Equals(node1)) return true;

            // If the parent node is not null or equal to the first node, 
            // call the ContainsNode method recursively using the parent of 
            // the second node.
            return ContainsNode(node1, node2.Parent);
        }







    } --------------------编程问答-------------------- 我没实现过,但大体的思路应该差不多(实现前提:把treeview的回发用脚本屏蔽掉):
0、给treeview 加 onmouseup 事件
1、定义一个公共变量记录是否处于右键点击状态
2、定义一个公共变量用与保存右键点击的节点
3、给treeview给鼠标单机事件,在事件内判断是否为右键点击. 
4、在treeview事件点击事件 selectedNode中,判断:若处于右键点击状态则将此节点记忆的公共变量内。
5、在 onmouseup事件中监听处于右键点击状态下鼠标的坐标。
6、把该节点的cloneNode插入到当前位置。
7、删除原节点。

只能全部用脚本操作,挺麻烦的。 建议你先看下treeview生成的源码,以及treeview本身自带的脚本事件 --------------------编程问答-------------------- 这么麻烦 我肯定用ext做 --------------------编程问答--------------------
引用 3 楼 sh524555685 的回复:
问题一:给treeview加鼠标事件 参考
问题二:判断右键
问题三:取按下键盘键值

WINFORM 不是WEB.
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,