小波快跑

VB.NET的忠实追随

用VB.NET作个个性播放器_Ⅱ

下面是代码:
Public Class Form1
    Inherits System.Windows.Forms.Form
    Dim a As Integer

#Region " Windows 窗体设计器生成的代码 "    Public Sub New()
        MyBase.New()
        '该调用是 Windows 窗体设计器所必需的。
        InitializeComponent()
        '在 InitializeComponent() 调用之后添加任何初始化
    End Sub
    '窗体重写 dispose 以清理组件列表。
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Windows 窗体设计器所必需的

    Private components As System.ComponentModel.IContainer

    '注意: 以下过程是 Windows 窗体设计器所必需的
    '可以使用 Windows 窗体设计器修改此过程。
    '不要使用代码编辑器修改它。
    Friend WithEvents AxMediaPlayer1 As AxMediaPlayer.AxMediaPlayer
    Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
    Friend WithEvents Button2 As System.Windows.Forms.Button

    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
        Me.AxMediaPlayer1 = New AxMediaPlayer.AxMediaPlayer
        Me.ListBox1 = New System.Windows.Forms.ListBox
        Me.Button1 = New System.Windows.Forms.Button
        Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog
        Me.Button2 = New System.Windows.Forms.Button
        CType(Me.AxMediaPlayer1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'AxMediaPlayer1
        '
        Me.AxMediaPlayer1.Location = New System.Drawing.Point(24, 224)
        Me.AxMediaPlayer1.Name = "AxMediaPlayer1"
        Me.AxMediaPlayer1.OcxState = CType(resources.GetObject("AxMediaPlayer1.OcxState"), System.Windows.Forms.AxHost.State)
        Me.AxMediaPlayer1.Size = New System.Drawing.Size(312, 46)
        Me.AxMediaPlayer1.TabIndex = 0
        '
        'ListBox1
        '
        Me.ListBox1.BackColor = System.Drawing.Color.FromArgb(CType(128, Byte), CType(128, Byte), CType(255, Byte))
        Me.ListBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.ListBox1.ForeColor = System.Drawing.Color.DarkGreen
        Me.ListBox1.ItemHeight = 16
        'Me.ListBox1.Items.AddRange(New Object() {"C:\歌曲\MP3\四面楚歌.mp3"})
        Me.ListBox1.Location = New System.Drawing.Point(24, 48)
        Me.ListBox1.Name = "ListBox1"
        Me.ListBox1.Size = New System.Drawing.Size(312, 178)
        Me.ListBox1.TabIndex = 2
        '
        'Button1
        '
        Me.Button1.FlatStyle = System.Windows.Forms.FlatStyle.Popup
        Me.Button1.ForeColor = System.Drawing.Color.Magenta
        Me.Button1.Image = CType(resources.GetObject("Button1.Image"), System.Drawing.Image)
        Me.Button1.Location = New System.Drawing.Point(24, 24)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(48, 24)
        Me.Button1.TabIndex = 3
        Me.Button1.Text = "Add"
        '
        'Button2
        '
        Me.Button2.FlatStyle = System.Windows.Forms.FlatStyle.Popup
        Me.Button2.ForeColor = System.Drawing.Color.Magenta
        Me.Button2.Image = CType(resources.GetObject("Button2.Image"), System.Drawing.Image)
        Me.Button2.Location = New System.Drawing.Point(72, 24)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(48, 24)
        Me.Button2.TabIndex = 3
        Me.Button2.Text = "Mov"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(8, 19)
        Me.BackgroundImage = CType(resources.GetObject("$this.BackgroundImage"), System.Drawing.Image)
        Me.ClientSize = New System.Drawing.Size(368, 301)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.ListBox1)
        Me.Controls.Add(Me.AxMediaPlayer1)
        Me.Controls.Add(Me.Button2)
        Me.Font = New System.Drawing.Font("宋体", 12.0!)
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.MaximizeBox = False
        Me.Name = "Form1"
        Me.ShowInTaskbar = False
        Me.Text = "player"
        CType(Me.AxMediaPlayer1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ListBox1.Select()
        Me.FormBorderStyle = FormBorderStyle.Fixed3D
        a = 0
        If ListBox1.Items.Count <> 0 Then
            Me.AxMediaPlayer1.FileName = ListBox1.Items(0)
        Else
            Dim i As Integer
            OpenFileDialog1.Multiselect = True
            OpenFileDialog1.ShowDialog()
            If OpenFileDialog1.FileName <> "" Then
                For i = 0 To OpenFileDialog1.FileNames.Length - 1
                    ListBox1.Items.Add(OpenFileDialog1.FileNames(i))
                Next
                Me.AxMediaPlayer1.FileName = ListBox1.Items(0)
            End If

        End If
    End Sub


    Private Sub AxMediaPlayer1_EndOfStream(ByVal sender As Object, ByVal e As AxMediaPlayer._MediaPlayerEvents_EndOfStreamEvent) Handles AxMediaPlayer1.EndOfStream

        a = a + 1
        If a <> ListBox1.Items.Count Then
            Me.AxMediaPlayer1.FileName = Me.ListBox1.Items(a)
            ListBox1.ClearSelected()
        Else
            a = 0
            Me.AxMediaPlayer1.FileName = ListBox1.Items(0)
            ListBox1.ClearSelected()
        End If
    End Sub

    Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
        Me.AxMediaPlayer1.FileName = ListBox1.SelectedItem
        ListBox1.ClearSelected()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim i As Integer
        Dim h As Integer
        h = ListBox1.Items.Count
        OpenFileDialog1.Multiselect = True
        OpenFileDialog1.ShowDialog()
        If OpenFileDialog1.FileName <> "" Then

            For i = 0 To OpenFileDialog1.FileNames.Length - 1
                ListBox1.Items.Add(OpenFileDialog1.FileNames(i))
            Next
            Me.AxMediaPlayer1.FileName = ListBox1.Items(h)

        End If
        ListBox1.ClearSelected()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If ListBox1.SelectedItem <> "" Then
            ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
        End If

    End Sub

 
End Class

posted on 2005-11-18 09:49  洪天飞雪  阅读(1094)  评论(1)    收藏  举报

导航