我想做一个鼠标悬停事件,当鼠标悬停在按钮上时我想更改按钮文字的颜色和字体大小,我试过这段代码但是没有工作:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
...
<asmv3:application>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>True/PM</dpiAware>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2,PerMonitor</dpiAwareness>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>
任何人都可以给我一个建议,我已经在谷歌搜索并尝试使用鼠标事件处理程序的不同方法,但没有工作。
答案 0 :(得分:2)
首先,您可以依靠按钮的 MouseEnter 和 MouseLeave 事件,而不是跟踪每次鼠标移动。
其次,不要忘记在事件处理程序的声明中添加Handles <Control>.<Event>
条款。
结果:
Private Sub Command1_MouseEnter(sender As Object, e As EventArgs) _
Handles Command1.MouseEnter
Command1.FontSize = 10
End Sub
Private Sub Command1_MouseLeave(sender As Object, e As EventArgs) _
Handles Command1.MouseLeave
Command1.FontSize = 8
End Sub
另外请不要忘记有些用户更喜欢键盘控制。 这意味着
答案 1 :(得分:1)
您可以尝试对MouseEnter和MouseLeave进行更改
Private Sub RightButton_MouseEnter(sender As System.Object, e As System.EventArgs) Handles RightButton.MouseEnter
RightButton.ForeColor = Color.AliceBlue
RightButton.Font = New Font(RightButton.Font, 12)
End Sub
Private Sub RightButton_MouseLeave(sender As System.Object, e As System.EventArgs) Handles RightButton.MouseLeave
RightButton.ForeColor = Color.White
RightButton.Font = New Font(RightButton.Font, 10)
End Sub