0

对不起我的英文写作我是 VB.Net 的新手。我有一个按钮,它使用鼠标悬停和鼠标离开来更改图像,将图像背景设置为图片。问题是在事件之后加载图像时看起来很慢。有什么方法可以提高性能吗?

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Button1.BackgroundImage = My.Resources._1 
End Sub

Private Sub Button1_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseHover
    Button1.BackgroundImage = My.Resources._2
End Sub

Private Sub Button1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave
    Button1.BackgroundImage = My.Resources._1
End Sub
4

1 回答 1

2

不是图像加载速度慢,而是它需要触发 MouseHover 事件的默认时间这里是有关该mousehovertime的更多信息,它似乎只能通过 API 在系统范围内设置。

另一种方法是使用 MouseEnter 而不是 MouseHover

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Button1.BackgroundImage = My.Resources._1
End Sub
'use a MouseEnter event instead
Private Sub Button1_MouseEnter(sender As Object, e As EventArgs) Handles Button1.MouseEnter
    Button1.BackgroundImage = My.Resources._2
End Sub

Private Sub Button1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave
    Button1.BackgroundImage = My.Resources._1
End Sub
于 2013-08-12T22:17:25.080 回答