using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace music_play { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btpaht_Click(object sender, EventArgs e) { DialogResult pathok; pathok = fBDpath.ShowDialog(); //显示选择目录对话框 if (pathok == DialogResult.OK) //如果单击OK 则获取目录内 { string[] allfile = System.IO.Directory.GetFiles(fBDpath.SelectedPath); //获取目录内所有文件 foreach (string file in allfile) { if (System.IO.Path.GetExtension(file) == ".mp3") { lBoxMouse.Items.Add(System.IO.Path.GetFileName(file)); //在LISTBOX里显示mp3格式文件 } } } } private void lBoxMouse_DoubleClick(object sender, EventArgs e) { try { axWindowsMediaPlayer1.URL = fBDpath.SelectedPath + @"/" + lBoxMouse.Items[lBoxMouse.SelectedIndex].ToString(); } catch { } } } }