单击后如何更改图像按钮的图像?
How to change the image of an Image Button once clicked?
我试图在单击 Bunifu 图像按钮后更改它的图像,因为它是一个音量 on/off 按钮。但是我的代码有一个例外,说 "path is not a legal form".
这是我的代码:
Private Sub BtnMute_Click(sender As Object, e As EventArgs) Handles BtnMute.Click
Dim OpenFileDialog As New OpenFileDialog
Dim Filename = "D:\Storage\Team Tag\Corporation\Corporation 3D Logo (PNG).png"
Dim mute As New System.Drawing.Bitmap(OpenFileDialog.FileName)
If MissionBriefingPlayer.settings.volume > 0 Then
MissionBriefingPlayer.settings.volume = 0
BtnMute.Image = mute
Else
MissionBriefingPlayer.settings.volume = 100
End If
End Sub
不需要OpenFileDialog
。
这是一个更好的方法。另外,您可以做的另一件事是在取消静音时不要将音量设置为 100,而是在静音之前将音量保存在静态变量中,然后在取消静音时将其设置回保存的音量:
Private Sub BtnMute_Click(sender As Object, e As EventArgs) Handles BtnMute.Click
Static _savedVolume as Integer = 0
If MissionBriefingPlayer.settings.volume > 0 Then
_savedVolume = MissionBriefingPlayer.settings.volume
MissionBriefingPlayer.settings.volume = 0
BtnMute.Image = New System.Drawing.Bitmap("D:\Storage\Team Tag\Corporation\Corporation 3D Logo (PNG).png")
Else
MissionBriefingPlayer.settings.volume = _savedVolume
End If
End Sub
我试图在单击 Bunifu 图像按钮后更改它的图像,因为它是一个音量 on/off 按钮。但是我的代码有一个例外,说 "path is not a legal form".
这是我的代码:
Private Sub BtnMute_Click(sender As Object, e As EventArgs) Handles BtnMute.Click
Dim OpenFileDialog As New OpenFileDialog
Dim Filename = "D:\Storage\Team Tag\Corporation\Corporation 3D Logo (PNG).png"
Dim mute As New System.Drawing.Bitmap(OpenFileDialog.FileName)
If MissionBriefingPlayer.settings.volume > 0 Then
MissionBriefingPlayer.settings.volume = 0
BtnMute.Image = mute
Else
MissionBriefingPlayer.settings.volume = 100
End If
End Sub
不需要OpenFileDialog
。
这是一个更好的方法。另外,您可以做的另一件事是在取消静音时不要将音量设置为 100,而是在静音之前将音量保存在静态变量中,然后在取消静音时将其设置回保存的音量:
Private Sub BtnMute_Click(sender As Object, e As EventArgs) Handles BtnMute.Click
Static _savedVolume as Integer = 0
If MissionBriefingPlayer.settings.volume > 0 Then
_savedVolume = MissionBriefingPlayer.settings.volume
MissionBriefingPlayer.settings.volume = 0
BtnMute.Image = New System.Drawing.Bitmap("D:\Storage\Team Tag\Corporation\Corporation 3D Logo (PNG).png")
Else
MissionBriefingPlayer.settings.volume = _savedVolume
End If
End Sub