Вот набросал проект как раз по той теме что тебе нужно посмотри как я делаю и поймешь:
Код | using System; using System.Collections; using System.IO; using System.Text; using System.Windows.Forms;
namespace WindowsFormsApplication1 { public partial class MainFrom : Form { public ArrayList playlist = new ArrayList();
public enum Track { Next, Back, Delete, Random }
public MainFrom() { InitializeComponent(); }
private void Get_Track_Click(object sender, EventArgs e) { playlist.Clear(); Get_playlist(); Update_playList(); }
private void Delete_Track_Click(object sender, EventArgs e) { Play_List(Track.Delete); }
private void Next_track_Click(object sender, EventArgs e) { Play_List(Track.Next); }
private void Back_track_Click(object sender, EventArgs e) { Play_List(Track.Back); }
private void Random_Track_Click(object sender, EventArgs e) { Play_List(Track.Random); }
private void Play_List(Track change_event) { switch (change_event) { case Track.Next: if (PlayListBox.SelectedIndex < PlayListBox.Items.Count - 1) { PlayListBox.SelectedIndex = PlayListBox.SelectedIndex + 1; } break; case Track.Back: if (PlayListBox.SelectedIndex > 0) { PlayListBox.SelectedIndex = PlayListBox.SelectedIndex - 1; } break; case Track.Random: if (PlayListBox.Items.Count > 0) { Random Random_Track = new Random(); int track_rnd = Random_Track.Next(0, PlayListBox.Items.Count); PlayListBox.SelectedItem = PlayListBox.Items[track_rnd].ToString(); } break; case Track.Delete: if (PlayListBox.Items.Count >= 0) { int index = PlayListBox.SelectedIndex; playlist.Remove(PlayListBox.SelectedItem);
if (PlayListBox.Items.Count > 1) { if (index == 0) { index = 0; } else { index = index - 1; } Update_playList(); PlayListBox.SelectedIndex = index; } else { Update_playList(); string[] text = play_status.Text.Split(':'); play_status.Text = text[0] + ": Список пуст!"; } } break; }
}
private void Get_playlist() { playlist.AddRange(File.ReadAllLines("playlist.txt", Encoding.GetEncoding(1251))); }
private void Update_playList() { BindingSource DataBind = new BindingSource(); DataBind.DataSource = playlist; PlayListBox.DataSource = DataBind; }
private void PlayListBox_SelectedIndexChanged(object sender, EventArgs e) { string[] text = play_status.Text.Split(':'); play_status.Text = text[0] + ": " + PlayListBox.SelectedItem; }
private void button1_Click(object sender, EventArgs e) { MessageBox.Show("*****Тут твоя функция для воспроизведения*****\n\r\n\r" + "Выбран элемент: " + PlayListBox.SelectedItem.ToString()); }
} }
|
А вот сам проект:
|