A Button To Select The Next Item In A List Box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MasterStarr
    New Member
    • May 2010
    • 1

    #1

    A Button To Select The Next Item In A List Box

    I Have A Music Player I Made Using A Tutorial In Visual basic 2008 And The Play Button For This Player Plays The Songs Fine, But The Problem Is The Code:

    Code:
    AxWindowsMediaPlayer1.Ctlcontrols.next()
    Does Not Play The Next Song Imported Into The List Box. So Rather Than Playing Around With That I Figured It Would Be Easier To Have A Button That Will Just Select The Next Item In The List Box (Becuase The Windows Media Player Tool Is Playing Songs Imported Into The List Box) . Unfortunately I Have No Idea how To Do That, So I Was Hoping Someone Could Help me Out?

    Code:
    Public Class Form1
    
        Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer
    
        Private Sub shadows_load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            Timer1.Enabled = True
            Timer1.Interval = 1
    
        End Sub
    
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    
            Dim F12key As Boolean
            Dim F11key As Boolean
    
            F12key = GetAsyncKeyState(Keys.F12)
            F11key = GetAsyncKeyState(Keys.F11)
    
            If F12key = True Then
                AxWindowsMediaPlayer1.URL = Listbox1.SelectedItem
    
            End If
    
            If F11key = True Then
                AxWindowsMediaPlayer1.Ctlcontrols.stop()
    
            End If
    
    
        End Sub
    
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        OpenFileDialog1.ShowDialog()
    End Sub
    
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        AxWindowsMediaPlayer1.URL = Listbox1.SelectedItem
    End Sub
    
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        AxWindowsMediaPlayer1.Ctlcontrols.stop()
    End Sub
    
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        AxWindowsMediaPlayer1.Ctlcontrols.pause()
    End Sub
    
    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        AxWindowsMediaPlayer1.Ctlcontrols.next()
    End Sub
    
    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        AxWindowsMediaPlayer1.Ctlcontrols.previous()
    End Sub
    
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
    End Sub
    
        Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
            For Each track As String In OpenFileDialog1.FileNames
                Listbox1.Items.Add(track)
            Next
    
        End Sub
    
    
        Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    
    
    
        End Sub
    End Class
    Also Just Ignore This Part
    Code:
    Public Class Form1
    
        Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer
    
        Private Sub shadows_load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            Timer1.Enabled = True
            Timer1.Interval = 1
    
        End Sub
    
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    
            Dim F12key As Boolean
            Dim F11key As Boolean
    
            F12key = GetAsyncKeyState(Keys.F12)
            F11key = GetAsyncKeyState(Keys.F11)
    
            If F12key = True Then
                AxWindowsMediaPlayer1.URL = Listbox1.SelectedItem
    
            End If
    
            If F11key = True Then
                AxWindowsMediaPlayer1.Ctlcontrols.stop()
    
            End If
    
    
        End Sub
    Thats Just A Universal Hotkey, Which Already Works Fine.
  • Guido Geurs
    Recognized Expert Contributor
    • Oct 2009
    • 767

    #2
    dear,

    I have used next code in VB6 (can be used in VB2008 ????)

    Code:
    Private Sub Com_down_play_Click()
    ' select next in the list
       With FileListBox
          If .ListIndex < .ListCount - 1 Then .Selected(.ListIndex + 1) = True
       End With
       With MMControl
             .Command = "Stop"
             .Command = "Close"
             .FileName = FileListBox.Path & "\" & FileListBox.FileName
             .Command = "Open"
             .From = Val(Text_seconden) * 1000
             .Command = "Play"
       End With
    End Sub
    Hope this will help

    Comment

    Working...