c# 利用 两个TREEVIEW控件完成TEENODE的鼠标拖动操作
功能说明:
我们有两个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的鼠标拖动操作的更多相关文章
- 利用深搜和宽搜两种算法解决TreeView控件加载文件的问题。
利用TreeView控件加载文件,必须遍历处所有的文件和文件夹. 深搜算法用到了递归. using System; using System.Collections.Generic; using Sy ...
- 在TreeView 控件上,如果双击任何一个节点的checkbox 只会收到一次After_Check事件 但是check属性变化两次(从false到true 再从true到false),请问该如何解决,谢谢!
在TreeView 控件上,如果双击任何一个节点的checkbox 只会收到一次After_Check事件 但是check属性变化两次(从false到true 再从true到false),请问该如何解 ...
- asp TreeView控件的使用
相对于之前发过一个TreeView控件的使用方法 本次利用js操作,页面无刷新,性能提高 Css编码可能时我的模板页样式被继承下来,导致页面变乱,不需要的可以去掉 前台 <style> . ...
- C#Winform中treeView控件使用总结
1.如何展开结点时改变图标(注意:不是选中时) 要在目录中使用图标首先要加入一个控件ImageList(命名为imageList1),然后可以按图片的index或名称引用图片. 然后需要在TreeVi ...
- VB TreeView控件使用详解
来源:http://www.newxing.com/Tech/Program/VisualBasic/TreeView_587.html 三小时快速掌握TreeView树状控件的使用.能不能掌握控件的 ...
- WinForm开发中针对TreeView控件改变当前选择节点的字体与颜色
本文转载:http://www.cnblogs.com/umplatform/archive/2012/08/29/2660240.html 在B/S开发中,对TreeView控件要改变当前选中节点的 ...
- TreeView控件绑定数据库
1.在设计视图里面的代码 <form id="form1" runat="server"> <div> <h1>两个表< ...
- 自己用js写的两个日历控件
前一阵写了两个日历控件,做了简单的封装,发出来共朋友们参考. 第一个日历控件,条状的日历. (使用方法:调用initBarTime(id,evn),第一个参数是要渲染div的id,第二个参数是点击日期 ...
- C# TreeView 控件的综合使用方法
1.概述 该篇文章开发使用的语言c#,环境visualstudio2010,sql数据库.主要内容包括: (1)treeView控件添加根节点.子节点的基本方法,节点的删除. (2)把treeView ...
随机推荐
- BEvent_客制化BusinessEvent通过Workflow Event接受消息传递(案例)
2014-08-03 Created By BaoXinjian
- hdu 5444 Elven Postman 二叉树
Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Problem Descrip ...
- 用widthStep的方法来增加某范围的像素----与imageROI对比
//用widthStep的方法来增加某范围的像素 //作者:sandy //时间:2015-10-5 #include <cv.h> #include <highgui.h> ...
- mysql 批量插入
对于批量插入: 1.在建立唯一索引的情况下,,从前往后,如果遇到索引重复错误 则停止插入(前面的插入成功),错误后面的即使正确也不会插入 方法1:insert igore 后 解决此问题 (ignor ...
- [物理学与PDEs]书中一些对数学研究有用的引理
P 35--38 1. 若 ${\bf B}$ 为横场 ($\Div{\bf B}=0\ra {\bf k}\cdot {\bf B}=0\ra $ 波的振动方向与传播方向平行), 则 $$\bex ...
- 转-Activity中使用orientation属性讲解及需注意的问题
http://www.software8.co/wzjs/yidongkaifa/6504.html 今天遇到了一个关于orientation的问题查了点资料记录一下,只有点点滴滴的积累,才能让我们更 ...
- (转)zookeeper学习记录--附browser
转自:http://agapple.iteye.com/blog/1111377 背景 前段时间看了S4流计算引擎,里面使用到了zookeeper进行集群管理,所以也就花了点时间研究了下zookeep ...
- Mac 10.10下安装MySQL5.6.21提示安装失败
只要要在安装的第三步在自定里不要选Startup item就可以了
- java中使用正则表达式
1.用正则表达式分割字符串 Pattern SPLIT2 = Pattern.compile("[,]"); String[] tmpStrings1 = SPLIT2.split ...
- try-catch中的finally块
finally块定义在catch的最后,只能出现一次. 无论程序是否出错都会执行的快板!无条件执行