Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); } /// <summary> ///Click to play a previous song/// </summary> /// <param name= "Sender" ></param> /// <param name= "E" ></param> Private voidButton2_Click (Objectsender, EventArgs e) { //get the index of the currently selected song intindex =Listbox1.selectedindex; Index--; if(Index <0) {Index= ListBox1.Items.Count-1; } Listbox1.selectedindex=index; Sp. Soundlocation=List[index]; Sp. Play (); } /// <summary> ///Click to play the next song/// </summary> /// <param name= "Sender" ></param> /// <param name= "E" ></param> Private voidButton3_Click (Objectsender, EventArgs e) { //get the index of the currently selected song intindex =Listbox1.selectedindex; Index++; if(Index = =listBox1.Items.Count) {index=0; } //re-assigns the changed index to the index of the currently selected itemListbox1.selectedindex =index; Sp. Soundlocation=List[index]; Sp. Play (); } //the full path used to store music fileslist<string> list =Newlist<string>(); Private voidBtnopen_click (Objectsender, EventArgs e) {OpenFileDialog OFD=NewOpenFileDialog (); Ofd. Title="Please select a music file"; Ofd. InitialDirectory=@"C:\Users\hhlt_00\Desktop\Music"; Ofd. MultiSelect=true; Ofd. Filter="music files |*.wav| All files |*.*"; Ofd. ShowDialog (); //get the full path of all the files that we have selected in the folder string[] Path =OFD. FileNames; for(inti =0; I < path. Length; i++) { //load the file name of the music files into the listboxListBox1.Items.Add (Path.getfilename (path[i)); //put the full path of the music file into the generic collectionlist. ADD (Path[i]); } } /// <summary> ///implement double-click Playback/// </summary> /// <param name= "Sender" ></param> /// <param name= "E" ></param> ///SoundPlayer SP =NewSoundPlayer (); Private voidListbox1_doubleclick (Objectsender, EventArgs e) {sp. Soundlocation=List[listbox1.selectedindex]; Sp. Play (); } }
. NET Learning notes----2015-07-04 (music player)