当鼠标移动时有效突出显示 DataGridView 上的列和行
我试图突出显示鼠标所在的行和列。本质上,这意味着更改所有适当单元格的背景颜色。目前我正在尝试在 MouseMove 事件中执行此操作。然而,这导致性能缓慢。
有人建议我使用 WPF 以获得更好的性能,但我不想走那条路。有哪些方法可以提高 C# 的性能?
I am trying to highlight the row and column which the mouse is on. Essentially this means to change the background color of all the appropriate cells. Currently I am trying to do this in the MouseMove event. However, this is causing slow performance.
I was suggested to use WPF for better performance, however I do not wish to go that route. What are some ways in which I can improve performance within C#?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用
CellMouseEnter
事件;与MouseMove
不同,每次鼠标移动到新单元格上时,它仅触发一次,并且不需要单击单元格来触发事件。您可能应该处理CellMouseEnter
(用于突出显示新单元格)、CellMouseLeave
(用于取消突出显示旧单元格)以及可能的Leave
事件整个 DGV(以确保所有单元格均未突出显示)。Try the
CellMouseEnter
event; it fires only once each time the mouse moves over a new cell, unlikeMouseMove
, and it doesn't require clicking on the cell to fire the event. You should probably handle theCellMouseEnter
(for highlighting the new cell),CellMouseLeave
(for un-highlighting the old cell) and possibly theLeave
event of the entire DGV (to make sure all cells are unhighlighted).您可以使用 DataGridView.RowEnter 事件 仅当新行变为活动状态时才会发生。 msdn 链接显示的示例与您尝试完成的示例完全相同。
You can use DataGridView.RowEnter Event which occurs only when a new row becomes active. The msdn links shows exactly the same sample you are trying to accomplish.