抱歉我的英文写作 我是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
答案 0 :(得分: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