-
概要
- <script type="text/javascript">loadTOCNode(1, 'summary');</script>
-
本文介绍如何将一个 ToolTip 添加到 TreeView 控件的节点。 ToolTip 显示鼠标指针暂停在其 TreeNode 信息。 虽然没有 ToolTip 属性, TreeView 控件, 可用于 ToolTip 控件提供 ToolTip 功能。 本文中描述示例演示这通过使用 TreeView 控件显示星期几。 当鼠标指针暂停超过之一 TreeNote, 表示星期几 ToolTip 出现。
-
要求
-
<script type="text/javascript">loadTOCNode(2, 'summary');</script> 以下列表概括了推荐硬件、 软件、 网络结构, 以及 ServicePack 所需:
-
• MicrosoftVisualStudio.NET 或 Microsoft Visual Studio 2005 -
本文假定您已熟悉以下主题:
-
• Visual C# 语法 • Windows 窗体 -
创建并填充示例表单
- <script type="text/javascript">loadTOCNode(2, 'summary');</script>
-
1. Visual C# 中创建一个新 Windows 程序。 2. 将 TreeView 控件添加到 Form 1。 3. 向 Form 1 添加一个 ToolTip 控件。 -
TreeNote 添加 ToolTip
- <script type="text/javascript">loadTOCNode(2, 'summary');</script>
-
1. 将以下代码粘贴到 Form 1 Load 事件: // 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();
2. 将以下代码粘贴到 TreeView MouseMove 事件: // 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, ""); }
http://msdn2.microsoft.com/en-us/library/ms173077.aspx (http://msdn2.microsoft.com/en-us/library/ms173077.aspx)3. 保存并运行程序。 如果您暂停节点, 之一上将鼠标指针出现工具提示。