我正在使用Visual Basic制作MP3播放器 我做了一个" Recent Played",但我遇到了问题。
我的"最近播放的" (listbox1
)只会在Form1_Load
时更新
当我执行Label6_Click
时,相同的代码无法正常工作。
以下是将最近的歌曲加载到列表框中的行:
ListBox1.DataSource = My.Settings.Recent
以下是完整代码:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
ListBox1.DataSource = My.Settings.Recent
End Sub
Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click
OpenFileDialog1.ShowDialog()
Label5.Text = OpenFileDialog1.FileName
End Sub
Private Sub Label2_Click(sender As Object, e As EventArgs) Handles Label2.Click
Me.Close()
End Sub
Private Sub Label3_Click(sender As Object, e As EventArgs) Handles Label3.Click
Me.WindowState = FormWindowState.Maximized
End Sub
Private Sub Label4_Click(sender As Object, e As EventArgs) Handles Label4.Click
Me.WindowState = FormWindowState.Minimized
End Sub
Private Sub Label6_Click(sender As Object, e As EventArgs) Handles Label6.Click
If Label6.Text = "Play" Then
My.Settings.Recent.Add(System.IO.Path.GetFileName(OpenFileDialog1.FileName))
Call Update1()
My.Settings.Save()
WindowsMediaPlayer1.URL = Label5.Text
WindowsMediaPlayer1.Ctlcontrols.play()
Label6.Text = "Pause"
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
My.Settings.Recent.Clear()
ListBox1.DataSource = My.Settings.Recent
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
End Sub
Sub Update1()
ListBox1.DataSource = My.Settings.Recent
End Sub
End Class