您的位置:首页 > 编程语言 > C#

如何向 Visual C# 中 TreeNote 添加 ToolTip

2008-07-08 10:46 399 查看

概要

loadTOCNode(1, 'summary');

本文介绍如何将一个 ToolTip 添加到 TreeView 控件的节点。 ToolTip 显示鼠标指针暂停在其 TreeNode 信息。 虽然没有 ToolTip 属性, TreeView 控件, 可用于 ToolTip 控件提供 ToolTip 功能。

本文中描述示例演示这通过使用 TreeView 控件显示星期几。 当鼠标指针暂停超过之一 TreeNote, 表示星期几 ToolTip 出现。



回到顶端


要求

loadTOCNode(2, 'summary');
以下列表概括了推荐硬件、 软件、 网络结构, 以及 ServicePack 所需:

MicrosoftVisualStudio.NET 或 Microsoft Visual Studio 2005
[align=left]本文假定您已熟悉以下主题: [/align]

Visual C# 语法
Windows 窗体


回到顶端


创建并填充示例表单

loadTOCNode(2, 'summary');

1.Visual C# 中创建一个新 Windows 程序。
2.将 TreeView 控件添加到 Form 1。
3.向 Form 1 添加一个 ToolTip 控件。


回到顶端


TreeNote 添加 ToolTip

loadTOCNode(2, 'summary');

1.将以下代码粘贴到 Form 1 Load 事件:
[code]// Create a root node.
TreeNode rootNode = treeView1.Nodes.Add("Day of Week");

// Create a series of child nodes and then set the Tag property for each.
for (int count = 0; count <= 6; count++)
{
DayOfWeek day = (DayOfWeek)count;
TreeNode childNode = rootNode.Nodes.Add(day.ToString());
childNode.Tag = "This day is " + day.ToString() + ".";
}

// Expand all of the TreeView nodes.
rootNode.ExpandAll();

[/code]
2.将以下代码粘贴到 TreeView MouseMove 事件:
[code]// Get the node at the current mouse pointer location.
TreeNode theNode =  this.treeView1.GetNodeAt(e.X, e.Y);

// Set a ToolTip only if the mouse pointer is actually paused on a node.
if ((theNode != null))
{
// Verify that the tag property is not "null".
if (theNode.Tag != null)
{
// Change the ToolTip only if the pointer moved to a new node.
if (theNode.Tag.ToString()!=this.toolTip1.GetToolTip(this.treeView1))
{
this.toolTip1.SetToolTip(this.treeView1, theNode.Tag.ToString());
}
}
else
{
this.toolTip1.SetToolTip(this.treeView1, "");
}
}
else     // Pointer is not over a node so clear the ToolTip.
{
this.toolTip1.SetToolTip(this.treeView1, "");
}

[/code]注意 : 代码应更改 Visual Studio 2005 中。 当您创建 WindowsForms 项目, VisualC # 将一个表单添加到项目默认。 此表单名为 Form 1。 表示形式两文件命名为 Form 1 和 Form1.designer.cs。 Form 1 中编写代码。 designer.cs 文件是其中 WindowsForms 设计器编写代码实现所有操作执行通过拖放控件从工具箱。 请有关 WindowsForms 设计器在 Visual C# 2005, 访问以下 MicrosoftWeb 站点:
http://msdn2.microsoft.com/en-us/library/ms173077.aspx (http://msdn2.microsoft.com/en-us/library/ms173077.aspx)
3.保存并运行程序。 如果您暂停节点, 之一上将鼠标指针出现工具提示。


回到顶端
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: