当鼠标移动时有效突出显示 DataGridView 上的列和行

发布于 2024-09-19 16:45:22 字数 141 浏览 1 评论 0原文

我试图突出显示鼠标所在的行和列。本质上,这意味着更改所有适当单元格的背景颜色。目前我正在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

迷离° 2024-09-26 16:45:22

尝试使用 CellMouseEnter 事件;与 MouseMove 不同,每次鼠标移动到新单元格上时,它仅触发一次,并且不需要单击单元格来触发事件。您可能应该处理 CellMouseEnter (用于突出显示新单元格)、CellMouseLeave (用于取消突出显示旧单元格)以及可能的 Leave 事件整个 DGV(以确保所有单元格均未突出显示)。

Try the CellMouseEnter event; it fires only once each time the mouse moves over a new cell, unlike MouseMove, and it doesn't require clicking on the cell to fire the event. You should probably handle the CellMouseEnter (for highlighting the new cell), CellMouseLeave(for un-highlighting the old cell) and possibly the Leave event of the entire DGV (to make sure all cells are unhighlighted).

删除会话 2024-09-26 16:45:22

您可以使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文