功能说明:

  我们有两个TREEVIEW控件——TREEVIEW1,TREEVIEW2。Treeview1内有三个NODE,Treeview2内有三个NODE。将Treeview1内的NODE拖动到Treeview2内,成为treeview2 NODE的子节点。

功能实现:

1:创建中间变量。

  Point myPoint = new Point();//记录鼠标尾随坐标

  TreeNode node;//记录要拖动的treeview1内的NODE

  添加Button Button1 控件实现treenode鼠标拖动尾随显示

2:添加FORM,TREEVIEW1,TREEVIEW2的鼠标MOVE动作,treeview1的鼠标DOWN动作,treeview2的鼠标UP动作。

  

private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Point myPosition = Control.MousePosition;
myPosition.Offset(myPoint.X - this.DesktopLocation.X, myPoint.Y - this.DesktopLocation.Y - 20);
button1.Location = myPosition;//this.DesktopLocation = myPosition;
}
}

private void treeView1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Point myPosition = Control.MousePosition;
myPosition.Offset(myPoint.X - this.DesktopLocation.X, myPoint.Y - this.DesktopLocation.Y);
button1.Location = myPosition;//this.DesktopLocation = myPosition;
}
}

private void treeView2_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Point myPosition = Control.MousePosition;
myPosition.Offset(myPoint.X - this.DesktopLocation.X, myPoint.Y - this.DesktopLocation.Y+20);
//button1.Location = myPosition;//this.DesktopLocation = myPosition;
int x=myPosition.X-treeView2.Location.X, y=myPosition.Y-treeView2.Location.Y;
foreach(TreeNode node in treeView2.Nodes)
{
if(e.Y>node.Bounds.Y && e.Y<node.Bounds.Y+node.Bounds.Height-1)
{
node.Checked = true;
button1.Text = node.Text;
break;
}
}
label1.Text = x.ToString();
label2.Text = y.ToString();
label3.Text = e.X.ToString();
label4.Text = e.Y.ToString();
}
}

private void treeView1_MouseDown(object sender, MouseEventArgs e)
{
myPoint = new Point(-e.X, -e.Y);
int x = -e.X - this.DesktopLocation.X - treeView1.Location.X, y = -e.Y - this.DesktopLocation.Y - treeView1.Location.Y;
foreach (TreeNode node in treeView1.Nodes)
{
if (e.Y > node.Bounds.Y && e.Y < node.Bounds.Y + node.Bounds.Height - 1)
{
this.node = new TreeNode();
this.node.Text=node.Text;
this.node.Name = node.Name;
button1.Text = this.node.Text;
break;
}
}
}

private void treeView2_MouseUp(object sender, MouseEventArgs e)
{
Point myPosition = Control.MousePosition;
myPosition.Offset(myPoint.X - this.DesktopLocation.X, myPoint.Y - this.DesktopLocation.Y);
button1.Location = myPosition;//this.DesktopLocation = myPosition;
int x = myPosition.X - treeView2.Location.X, y = myPosition.Y - treeView2.Location.Y;
foreach (TreeNode node in treeView2.Nodes)
{
if (e.Y > node.Bounds.Y && e.Y < node.Bounds.Y + node.Bounds.Height - 1)
{
node.Checked = true;
node.Nodes.Add(this.node);
break;
}
}
}

c# 利用 两个TREEVIEW控件完成TEENODE的鼠标拖动操作的更多相关文章

  1. 利用深搜和宽搜两种算法解决TreeView控件加载文件的问题。

    利用TreeView控件加载文件,必须遍历处所有的文件和文件夹. 深搜算法用到了递归. using System; using System.Collections.Generic; using Sy ...

  2. 在TreeView 控件上,如果双击任何一个节点的checkbox 只会收到一次After_Check事件 但是check属性变化两次(从false到true 再从true到false),请问该如何解决,谢谢!

    在TreeView 控件上,如果双击任何一个节点的checkbox 只会收到一次After_Check事件 但是check属性变化两次(从false到true 再从true到false),请问该如何解 ...

  3. asp TreeView控件的使用

    相对于之前发过一个TreeView控件的使用方法 本次利用js操作,页面无刷新,性能提高 Css编码可能时我的模板页样式被继承下来,导致页面变乱,不需要的可以去掉 前台 <style> . ...

  4. C#Winform中treeView控件使用总结

    1.如何展开结点时改变图标(注意:不是选中时) 要在目录中使用图标首先要加入一个控件ImageList(命名为imageList1),然后可以按图片的index或名称引用图片. 然后需要在TreeVi ...

  5. VB TreeView控件使用详解

    来源:http://www.newxing.com/Tech/Program/VisualBasic/TreeView_587.html 三小时快速掌握TreeView树状控件的使用.能不能掌握控件的 ...

  6. WinForm开发中针对TreeView控件改变当前选择节点的字体与颜色

    本文转载:http://www.cnblogs.com/umplatform/archive/2012/08/29/2660240.html 在B/S开发中,对TreeView控件要改变当前选中节点的 ...

  7. TreeView控件绑定数据库

    1.在设计视图里面的代码 <form id="form1" runat="server"> <div> <h1>两个表< ...

  8. 自己用js写的两个日历控件

    前一阵写了两个日历控件,做了简单的封装,发出来共朋友们参考. 第一个日历控件,条状的日历. (使用方法:调用initBarTime(id,evn),第一个参数是要渲染div的id,第二个参数是点击日期 ...

  9. C# TreeView 控件的综合使用方法

    1.概述 该篇文章开发使用的语言c#,环境visualstudio2010,sql数据库.主要内容包括: (1)treeView控件添加根节点.子节点的基本方法,节点的删除. (2)把treeView ...

随机推荐

  1. freemarker解析模板报错问题

    在确定模板文件代码无误的情况下,导致报错的原因大概有以下原因: 模板文件编码改变了(比如eclipse中的项目部署到tomcat下,而忘记设置tomcat编码就会导致读取模板文件编码不正确,导致程序解 ...

  2. RMAN_学习实验1_RMAN备份标准过程(案例)

    2014-12-23 Created By BaoXinjian

  3. Android屏幕适配建议

    一.关于布局适配 1.不要使用绝对布局 2.尽量使用match_parent 而不是fill_parent . 3.能够使用权重的地方尽量使用权重(android:layout_weight) 4.如 ...

  4. Jetty服务器jmx监控

    Jetty服务器jmx监控 Jetty 服务器增加jmx,jmx-remote模块 1.修改对应jetty服务器的配置文件start.ini追加如下两行–module=jmx–module=jmx-r ...

  5. 【jQuery】关于选择器中的 :first 、 :first-child 、 :first-of-type

    [:first] <!DOCTYPE html><html lang="zh-CN"><head>    <title>test&l ...

  6. iOS 程序打包,安装流程

    一.发布测试,是指将你的程序给   * 你的测试人员,因为程序总归是要测试的   * 你的客户,在正式发布之前,客户肯定是要先看(验收)的 在他们的iOS设备(iphone,ipod, ipad)安装 ...

  7. linux内核设计与实现--从内核出发

    linux内核有两种版本:稳定的和处于开发中的. linux通过一种简单的命名机制来区分稳定的和处于开发中的内核,使用3个或者4个“.”分割的数字来代表不同内核版本. 如:2.6.26.1:第一个数字 ...

  8. Dubbo 应用容器

    Dubbo的容器模块,是一个独立的容器,因为服务通常不需要Tomcat/JBoss等Web容器的特性,没必要用Web容器去加载服务. 服务容器只是一个简单的Main方法,并加载一个简单的Spring容 ...

  9. [SQL]详解CUBE和ROLLUP区别<使用rollup或cube通过交叉列可产生高级汇总结果集>

    要使用CUBE,首先要了解GROUP BY. 其实CUBE和ROLLUP区别不太大,只是在基于GROUP BY 子句创建和汇总分组的可能的组合上有一定差别,CUBE将返回的更多的可能组合.如果在GRO ...

  10. [ZOJ 1009] Enigma (模拟)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1009 题目大意:给你三个转换轮,只有当第一个转换轮转动一圈后第二 ...