如何向 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 |
• | 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. | 保存并运行程序。 如果您暂停节点, 之一上将鼠标指针出现工具提示。 |
回到顶端
相关文章推荐
- 如何给Ext.tree.ColumnTree添加搜索栏
- 如何在Centos7中添加Tree命令
- (转)jquery easyui treegrid使用小结 (主要讲的是如何编辑easyui中的行信息包括添加 下拉列表等)
- 如何在TWaver Flex中定制Tree的tooltip
- 如何添加 其他控件到treelist上
- 如何向busybox添加自己的命令 例如:tree
- 在 Visual C# 中,如何为 TextBox 控件添加水印文字
- 如何在TWaver Flex中定制Tree的tooltip
- 如何为treewidgetitem添加右键菜单
- Flex Tree 如何在不选定节点的情况下进行添加(Demo)
- DEV的TreeList添加ToolTip信息
- linux如何给程序添加自启动
- [Struts2] 如何访问或添加request/session/application属性, 以及获取对象.
- NSPredicate里面如何添加NSDate进行筛选?
- 如何为JVM添加关闭钩子与简要分析
- 2017-02-20 可编辑div中如何在光标位置添加内容
- 服务器上如何再另外添加一个E盘
- sql server 2012 报表开发(3) Reporting Service 如何在数据列上添加超链接跳转
- 如何让ssh的时候不提示添加host key | 如何加快ssh登录的速度
- 如何使用DW工具给图片添加热点