-
C#教程之[原创][开源] SunnyUI.Net 开发日志:ListBox 增加跟随鼠标滑过高亮(3)
兄弟们,人家这花两年时间解决的,应该有用,继续再找找,又找到一篇洋文的:
https://stackoverflow.com/questions/1316027/listbox-drawitem-hotlight-state-in-the-ownerdraw-mode
It took me only two years to find the answer for you, but here it is:
The DrawItemState.HotLight only applies to owner drawn menus, not the listbox.
For the ListBox, you have to keep track of the item yourself:
看看,也是两年,估计上面中文的从这个翻译过来。
除了这俩,还真没找到。
继续撸代码,果真管用。不过还是有问题,鼠标滑快了,ListBox闪烁的厉害。
分析代码 listBox1.Invalidate(); 这是刷新全部的。鼠标滑过也就和本次选中和上次选中的有关系。
就刷这两个Item就行,有了思路,撸代码三连发:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
private int lastIndex = -1; private int mouseIndex = -1; [Browsable( false )] public int MouseIndex { get => mouseIndex; set { if (mouseIndex != value) { if (lastIndex >= 0 && lastIndex != SelectedIndex) { OnDrawItem( new DrawItemEventArgs( this .CreateGraphics(), Font, GetItemRectangle(lastIndex), lastIndex, DrawItemState.Grayed)); } mouseIndex = value; if (mouseIndex >= 0 && mouseIndex != SelectedIndex) { OnDrawItem( new DrawItemEventArgs( this .CreateGraphics(), Font, GetItemRectangle(value), value, DrawItemState.HotLight)); } lastIndex = mouseIndex; } } } protected override void OnMouseMove(MouseEventArgs e) { base .OnMouseMove(e); MouseIndex = IndexFromPoint(e.Location); } protected override void OnMouseLeave(EventArgs e) { base .OnMouseLeave(e); MouseIndex = -1; } |
栏目列表
最新更新
C# 面向对象
假设客车的座位数是9行4列,使用二维数
C#基于接口设计三层架构Unity篇
C#线程 入门
C#读取静态类常量属性和值
C# 插件式编程
C# 委托与事件有啥区别?
C#队列学习笔记:队列(Queue)和堆栈(Stack
linq 多表分组左连接查询查询统计
C#队列学习笔记:MSMQ入门一
C# 在Word中添加Latex 数学公式和符号
inncheck命令 – 检查语法
基于UDP的服务器端和客户端
再谈UDP和TCP
在socket编程中使用域名
网络数据传输时的大小端问题
socket编程实现文件传输功能
如何优雅地断开TCP连接?
图解TCP四次握手断开连接
详细分析TCP数据的传输过程
SqlServer 利用游标批量更新数据
BOS只读状态修改
SQL Server等待事件—PAGEIOLATCH_EX
数据库多行转换为单一列
获取数据表最后最后访问,修改,更新,
计算经历的时间
SQL查询结果自定义排序
修改数据库默认位置
日期简单加或减
从日期获取年,月或日