问题描述:
现在有一个TreeView,有N个TreeNode,现在要做的是,当鼠标移动到一个节点并停留2秒时显示这个节点的详细信息窗体,显示过程中鼠标还此节点上时,详细信息窗体一直不关闭,鼠标移动到详细信息窗体上也不关闭,从上面离开则马上关闭.
如果在2秒内移动另外节点,则另一个节点从0开时计时(2秒)再看是否显示详细信息.
如果移出现在TreeNode的范围且不在任何TreeNode上,如果详细信息还在show则关闭,否则什么也不做.另:在整个过程(任何地方)中出现鼠标单击或双击事件,都要关闭详细信息窗体效果类似于QQ好友信息搞要.以前是用NodeMouseHover做的,但是默认时问是20ms,实在太短.现分100,不够可以再加,最好有描述性代码或者好的思路也可以另:再加100分
现在有一个TreeView,有N个TreeNode,现在要做的是,当鼠标移动到一个节点并停留2秒时显示这个节点的详细信息窗体,显示过程中鼠标还此节点上时,详细信息窗体一直不关闭,鼠标移动到详细信息窗体上也不关闭,从上面离开则马上关闭.
如果在2秒内移动另外节点,则另一个节点从0开时计时(2秒)再看是否显示详细信息.
如果移出现在TreeNode的范围且不在任何TreeNode上,如果详细信息还在show则关闭,否则什么也不做.另:在整个过程(任何地方)中出现鼠标单击或双击事件,都要关闭详细信息窗体效果类似于QQ好友信息搞要.以前是用NodeMouseHover做的,但是默认时问是20ms,实在太短.现分100,不够可以再加,最好有描述性代码或者好的思路也可以另:再加100分
当treeview的mousehover 时间为2秒的时候就显示详细信息
然后显示详细信息用tooltip做
你试哈吧
加个TOOLTIP控件就可以看到这个属性了。
不知道帖主是的树是动态添加的还是死的
如果是动态的则要在表中添加一个字段如果是死的
那么在设计的时候 在属性中设置动态的则 load事件中
treeNode node=new treeNode();
node.Tooltip="显示的内容";tooltip 就是提示语的意思
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace 实验程序
{
public partial class Form6 : Form
{
TreeNode mhNode = new TreeNode(); //鼠标悬停所在的TreeNode
Rectangle mhNodeBound = new Rectangle(); //当前鼠标所在结点的矩形边界
MsgFrm msgFrm = new MsgFrm(); //详细信息窗体
Point msgFrmPosition = new Point(); //详细信息窗体的显示位置 public Form6()
{
InitializeComponent();
msgFrm.Owner = this;
} private void treeView1_NodeMouseHover(object sender, TreeNodeMouseHoverEventArgs e)
{
if (msgFrm.Visible == false)
{
mhNode = e.Node;
timer1.Stop();
timer1.Start();
mhNodeBound = e.Node.Bounds;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
msgFrm.Location = msgFrmPosition;
msgFrm.ShowText = mhNode.Text;
msgFrm.Visible = true;
this.Focus();
timer1.Stop();
} private void treeView1_Click(object sender, EventArgs e)
{
msgFrm.Visible = false;
} private void treeView1_MouseMove(object sender, MouseEventArgs e)
{
msgFrmPosition = treeView1.PointToScreen(e.Location);
if (e.X < mhNodeBound.Left || e.Y < mhNodeBound.Top || e.X > mhNodeBound.Right || e.Y > mhNodeBound.Bottom)
{
msgFrm.Visible = false;
}
} }
}
另外一个是详细信息窗体,里面放了一个Label表示你要显示的详细信息:
其中,设计器代码:namespace 实验程序
{
partial class MsgFrm
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null; /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
} #region Windows 窗体设计器生成的代码 /// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(39, 23);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(41, 12);
this.label1.TabIndex = 0;
this.label1.Text = "label1";
//
// MsgFrm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(123, 59);
this.ControlBox = false;
this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Name = "MsgFrm";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.MouseLeave += new System.EventHandler(this.MsgFrm_MouseLeave);
this.ResumeLayout(false);
this.PerformLayout(); } #endregion private System.Windows.Forms.Label label1;
}
}事件代码:using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace 实验程序
{
public partial class MsgFrm : Form
{
private string showText = ""; public string ShowText
{
get { return showText; }
set
{
showText = value;
label1.Text = showText;
}
} public MsgFrm()
{
InitializeComponent();
} Point curPosition = new Point();
protected override void OnMouseMove(MouseEventArgs e)
{
curPosition =this.PointToScreen(e.Location);
base.OnMouseMove(e);
} private void MsgFrm_MouseLeave(object sender, EventArgs e)
{
if (curPosition.X < this.Left || curPosition.Y < this.Top || curPosition.X > this.Right || curPosition.Y > this.Bottom)
{
this.Visible = false;
}
}
}
}
tooltip是行的,因为要涉及到图片的问题(DV的控件,坐标位置和MS标 准控件不兼容).
timer + 窗体(singleton) 已试过有点小问题.
另:GentleCat 的代码我试试,看能否做出来.
另:这几天CSDN是否是有问题?我打不开
另:怎么加分?是不是要隔几天,如果实在不行我再开一帖,进来拿分
劳烦解答!
今天我测试了一下,很抱歉只显示第一次,移到另外的节点没有显示出来,另坐标好像也有问题.另:换了个浏览器,IE出现问题了,我还以是CSDN有问题呢