Here is the add playlist code in C#
//toolstrip button to create new playlist
private void newPlaylistToolStripMenuItem_Click(object sender, EventArgs e)
{
//CreatePlaylist();
TabPage tab = new TabPage($"Playlist {tabControl1.TabPages.Count}");
tabControl1.TabPages.Add(tab);
ListBox listbox22 = new ListBox();
listbox22.Dock = DockStyle.Fill;
listbox22.SelectionMode = SelectionMode.MultiExtended;
tab.Controls.Add(listbox22);
}
Here is play button code:
private void Play_Click(object sender, EventArgs e)
{
double pausedPosition = WMPPlayer.Ctlcontrols.currentPosition;
WMPPlayer.URL = filepaths[listBox1.SelectedIndex];
WMPPlayer.Ctlcontrols.currentPosition = pausedPosition;
WMPPlayer.Ctlcontrols.play();
}
ADDING MUSIC TO TABS CODE:
private void addToPlaylistToolStripMenuItem_Click(object sender, EventArgs e)
{
(tabControl1.TabPages.Cast<TabPage>()
.FirstOrDefault(page => page.Text == tabControl1.SelectedTab.Text)
?.Controls.Cast<Control>()
.FirstOrDefault(control => control is ListBox) as ListBox)?.Items.Add(listBox1.SelectedItem);
listBox1.SelectionMode = SelectionMode.MultiExtended;
ListBox current_listbox = (ListBox)tabControl1.SelectedTab.Controls[0];
}
When we reference listbox1 in the play button code, that is the main listbox in the middle of the screen before you make any new tabs. This is a music player and the new tabs are playlists that users can add music to. When I try to play a song through the new tab, nothing plays. How can I make the play button play songs in these newly formed tabs/listboxes?