winfrom 树形控件如何实现鼠标经过节点时光标颜色改变效果

简介:   一、winform TreeView控件的实现方式。  ///         /// Handles the MouseMove event of the treeView1 control.

 

一、winform TreeView控件的实现方式。 

  ///   <summary>
        
///  Handles the MouseMove event of the treeView1 control.
        
///   </summary>
        
///   <param name="sender"> The source of the event. </param>
        
///   <param name="e"> The  <see cref="System.Windows.Forms.MouseEventArgs"/>  instance containing the event data. </param>
        
///   <remarks></remarks>
         private  void treeView1_MouseMove( object sender, MouseEventArgs e)
        {
            TreeView _TreeView = (TreeView)sender;
             // 通过鼠标的e.X和e.Y坐标来获取TreeNode。
            TreeNode _Node = treeView1.GetNodeAt(e.X, e.Y);
             if (_Node !=  null)
            {
                 // 防止出现闪烁。
                 if (_TreeView.Tag ==  null || !_TreeView.Tag.Equals(_Node))
                {
                    _TreeView.Refresh();
                    Graphics _Graphics = Graphics.FromHwnd(_TreeView.Handle);
                     // _Graphics.FillRectangle(new SolidBrush(Color.FromArgb(100, 0, 0, 255)), _Node.Bounds);
                    
// 重绘整行节点。
                    _Graphics.FillRectangle( new SolidBrush(Color.FromArgb( 10000255)),  new Rectangle( new Point( 0, _Node.Bounds.Y),  new Size( this.treeView1.Width, _Node.Bounds.Height)));
                    _Graphics.Dispose();
                    _TreeView.Tag = _Node;
                }
            }

        }



 参考文章:http: // topic.csdn.net/u/20091216/14/8df3c649-fb8b-4ee5-89f2-6ab8ad03f9cf.html
二、winform Devexpress TreeList控件的实现方式。
///   <summary>
        
///  Handles the MouseMove event of the treeList1 control.
        
///   </summary>
        
///   <param name="sender"> The source of the event. </param>
        
///   <param name="e"> The  <see cref="System.Windows.Forms.MouseEventArgs"/>  instance containing the event data. </param>
        
///   <remarks></remarks>
         private  void treeList1_MouseMove( object sender, MouseEventArgs e)
        {
            TreeList _TreeView = (TreeList)sender;
            Point mousePosition = Control.MousePosition;
             if (_TreeView.State == TreeListState.Regular)
            {
                TreeListHitInfo hitInfo = _TreeView.CalcHitInfo( new Point(e.X, e.Y));
                 if (hitInfo.HitInfoType == HitInfoType.Cell)
                {
                     // _TreeView.SetFocusedNode(hitInfo.Node);
                    
// 根据鼠标的e.X和e.Y来获取TreeListNode;而不能直接通过 _TreeView.FocusedNode来获取。
                    TreeListNode _Node = hitInfo.Node;
                     // TreeListNode _Node = _TreeView.FocusedNode; //  Winfrom 程序中这样获取的this.treeList1.GetNodeAt(e.X, e.Y);
                    Rectangle r = (_TreeView.ViewInfo.RowsInfo[_Node].Cells[ 0as DevExpress.XtraTreeList.ViewInfo.CellInfo).Bounds;
                     if (_Node !=  null)
                    {
                         // if (!_Node.Checked)
                        
// {
                            
// 防止出现闪烁。
                             if (_TreeView.Tag ==  null || !_TreeView.Tag.Equals(_Node))
                            {
                                _TreeView.Refresh();
                                Graphics _Graphics = Graphics.FromHwnd(_TreeView.Handle);
                                 //  _Graphics.FillRectangle(new SolidBrush(Color.FromArgb(100, 0, 0, 255)), r);
                                
// 重绘整行节点。
                                _Graphics.FillRectangle( new SolidBrush(Color.FromArgb( 10000255)),  new Rectangle( new Point( 0, r.Y),  new Size(_TreeView.Width, r.Height)));
                                _Graphics.Dispose();
                                _TreeView.Tag = _Node;
                            }
                         // }
                    }
                }
            }
        }

 
一、关于Devexpress控件的TreeListNode如何得到Point的问题。

可以参考http: // www.devexpress.com/Support/Center/p/Q203877.aspx

 二、关于Devexpress控件在MouseOver事件中如何得到当前鼠标的TreeListNode

可以参考http: // community.devexpress.com/forums/t/82086.aspx

 演示效果: 演示Demo下载

 

目录
相关文章
|
C# 索引 Windows
Winform控件优化之TabControl控件的使用和常用功能
TabControl是一个分页切换(tab)控件,不同的页框内可以呈现不同的内容,将主要介绍调整tab的左右侧显示、设置多行tab、禁用或删除tabpage、隐藏TabControl头部的选项卡等
7497 0
Winform控件优化之TabControl控件的使用和常用功能
|
9月前
|
搜索推荐 数据挖掘 API
京东详情 API 接口有什么应用与价值?
在电商蓬勃发展的今天,数据成为业务增长的核心。京东作为电商巨头,其详情API接口为开发者、商家和分析师提供了丰富的商品数据,包括描述、价格、库存和评价等,助力电商业务各个环节。本文将深入探讨该接口的应用场景与价值,并结合Python代码示例,帮助读者更好地理解和利用这一强大工具。 京东详情API接口不仅支持商品展示与搜索、数据分析与市场调研,还适用于竞品分析、智能推荐等场景。它为商家拓展销售渠道、优化运营决策、提升服务质量;为开发者快速创新、降低开发成本;为消费者提供更多选择、提高购物效率和个性化服务。通过实际代码示例,展示了如何调用API获取商品详情,为开发者提供操作指导。
254 12
|
设计模式 程序员 C#
C# 使用 WinForm MDI 模式管理多个子窗体程序的详细步骤
WinForm MDI 模式就像是有超能力一般,让多个子窗体井然有序地排列在一个主窗体之下,既美观又实用。不过,也要小心管理好子窗体们的生命周期哦,否则一不小心就会出现一些意想不到的小bug
1061 0
|
机器学习/深度学习 人工智能 Cloud Native
|
Linux Shell
Centos定期自动清理临时文件
简单Shell脚本清理临时文件 使用`cron`设置定时任务,如每天8点运行: 记得调整路径和脚本名以匹配你的环境。
314 5
|
Linux 网络安全 数据安全/隐私保护
|
监控 数据可视化 搜索推荐
ERP系统中的财务预测与预算编制解析
【7月更文挑战第25天】 ERP系统中的财务预测与预算编制解析
527 0
|
存储 NoSQL 大数据
【MongoDB】GridFS机制
【4月更文挑战第2天】【MongoDB】GridFS机制
|
算法 Python
探索LightGBM:并行化与分布式训练
探索LightGBM:并行化与分布式训练【2月更文挑战第4天】
921 1
|
Java
实现Java热部署的几种解决方案
百度百科:热部署,就是应用正在运行的时候就可以升级软件,而不需要重新启动应用。 spring-loaded 依赖 org.
2545 0