using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Runtime; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace YURAOKE { public partial class Form1 : Form { List allItems = new List(); public Form1() { InitializeComponent(); //listcollection.Clear(); //foreach (string str in listBox1.Items) //{ // listcollection.Add(str); //} } string[] files, paths; private void button1_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog1 = new OpenFileDialog(); if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK); { //this.textBox_path.Text = openFileDialog1.FileName(paths.GetFileName()); } } private void button2_Click(object sender, EventArgs e) { axWindowsMediaPlayer1.URL = textBox_path.Text; axWindowsMediaPlayer1.Ctlcontrols.play(); } private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { //axWindowsMediaPlayer1.URL = paths[listBox1.SelectedIndex]; } private void button4_Click(object sender, EventArgs e) { } private void textBoxSeach_TextChanged(object sender, EventArgs e) { for (int i = listBox1.Items.Count - 1; i >= 0; i--) { if (listBox1.Items[i].ToString().Contains(textBoxSearch.Text)) { listBox1.SetSelected(i, true); } else { listBox1.Items.RemoveAt(i); } } if (string.IsNullOrEmpty(textBoxSearch.Text)) { listBox1.SelectedItems.Clear(); AddListBoxItems(allItems); } } private void LoadItems() { using (var ofd = new OpenFileDialog() { Filter = "Audio file(*.mp3)|*.mp3|All files(*)|*", Multiselect = true, RestoreDirectory = true }) { if (ofd.ShowDialog() == DialogResult.OK) { var items = new List(); //get the filename for each file foreach (var name in ofd.FileNames) { //store first to lists items.Add(Path.GetFileName(name)); } //now add the items from List AddListBoxItems(items.ToArray()); allItems.AddRange(listBox1.Items.Cast().ToList()); } } } private void AddListBoxItems(IEnumerable items) { listBox1.BeginUpdate(); listBox1.Items.AddRange(items.ToArray() .Where(x => !listBox1.Items.Cast() .Any(item => x.Equals(item, StringComparison.InvariantCultureIgnoreCase))).ToArray()); listBox1.EndUpdate(); CountListBoxItems(); } private void CountListBoxItems() { label2.Text = listBox1.Items.Count.ToString(); } private void Form1_Load(object sender, EventArgs e) { } private void button3_Click(object sender, EventArgs e) { OpenFileDialog OpenFileDialog1 = new OpenFileDialog(); OpenFileDialog1.Multiselect = true; if (OpenFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { files = OpenFileDialog1.SafeFileNames; paths = OpenFileDialog1.FileNames; for (int i = 0; i < files.Length; i++) { listBox1.Items.Add(files[i]); } } } } }