标签:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; namespace boxs { public partial class Form1 : Form { public Form1() { InitializeComponent(); } List<string> a = new List<string>(); private void button1_Click(object sender, EventArgs e) { OpenFileDialog od = new OpenFileDialog(); od.Title = "xx"; od.InitialDirectory = @"C:\Documents and Settings\Administrator\桌面"; od.Filter = ""; od.Multiselect = true; od.ShowDialog(); string[] names = od.FileNames; foreach (string path in names) { string s_name = Path.GetFileName(path); listBox1.Items.Add(s_name); a.Add(path); } } private void listBox1_DoubleClick(object sender, EventArgs e) { string ax = Convert.ToString(a[listBox1.SelectedIndex]); axWindowsMediaPlayer1.URL = ax; this.button2.Text = "暂停"; } private bool b = false; private void button2_Click(object sender, EventArgs e) { if (this.button2.Text == "播放") { if (listBox1.Items.Count < 1 || listBox1.SelectedIndex<0) { MessageBox.Show("代码错了"); return; } if (b){ b = false; } else { string ax = Convert.ToString(a[this.listBox1.SelectedIndex]); axWindowsMediaPlayer1.URL = ax; } axWindowsMediaPlayer1.Ctlcontrols.play(); this.button2.Text = "暂停"; } else { axWindowsMediaPlayer1.Ctlcontrols.pause(); this.button2.Text = "播放"; b = true; } } private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { b = false; } } }
标签:
原文地址:http://www.cnblogs.com/mengluo/p/5484799.html