单击后如何更改图像按钮的图像



我试图在单击Bunifu映像按钮的图像,因为它是一个卷打开/关键按钮。但是我的代码有一个例外,上面说"路径不是法律形式"。

这是我的代码:

Private Sub BtnMute_Click(sender As Object, e As EventArgs) Handles BtnMute.Click
    Dim OpenFileDialog As New OpenFileDialog
    Dim Filename = "D:StorageTeam TagCorporationCorporation 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:StorageTeam TagCorporationCorporation 3D Logo (PNG).png")
    Else
        MissionBriefingPlayer.settings.volume = _savedVolume
    End If
End Sub

相关内容

  • 没有找到相关文章

最新更新