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 ...
随机推荐
- RMAN_Oracle RMAN的常用Configure配置
2014-12-09 Created By BaoXinjian
- PLSQL_性能优化效能跟踪工具SQL Trace分析(案例)
2014-06-25 Created By BaoXinjian
- 【初识】KMP算法入门(转)
感觉写的很好,尤其是底下的公式,易懂,链接:http://www.cnblogs.com/mypride/p/4950245.html 举个例子 模式串S:a s d a s d a s d f a ...
- java8 JDK8 元空间
一. JDK8 元空间概念 二. PermGen vs. Metaspace 运行时的比较 一. JDK8 元空间概念 很多开发者都在其系统中见过“java.lang.OutO ...
- SQL SERVER 中的 object_id()函数
在SQLServer数据库中,如果查询数据库中是否存在指定名称的索引或者外键约束等,经常会用到object_id('name','type')方法,做笔记如下: ? 语法:object_id('obj ...
- http 303 307 302 状态码理解
最近在看 <<the rails4 way>> 书中提到了这几个状态码,网上搜到几篇文章 http://www.cnblogs.com/cswuyg/p/3871976.htm ...
- Perl中文/unicode/utf8/GB2312之间的转换
参考:http://daimajishu.iteye.com/blog/959239不过具测试,也有错误:原文如下: # author: jiangyujieuse utf8; ##在最后一个例子, ...
- [JS]以下是JS省市联动菜单代码
以下是JS省市联动菜单代码: 代码一: <html> <head> <title></title> <script language=" ...
- Codeforces 119C DP
题意: 有n天,m门课和常数k; 每天上一门课,每门课程有两个属性,最少作业量a,最多作业量b,和难度c. 1<=a<=b<=1e16 c<=100 1<=n<=m ...
- [HDU 4419] Colourful Rectangle (扫描线 矩形面积并)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4419 题目大意:比矩形面积并多了颜色,问染成的每种颜色的面积. 矩形面积并的扫描线维护的是长度,这道题 ...