我试图在点击后更改我的Bunifu图像按钮的图像,因为它是一个音量开/关按钮。但我的代码有一个例外,即“路径不是法律形式”。
这是我的代码:
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
答案 0 :(得分:1)
不需要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