今日工作上一首控件的代码
private void button5_Click(object sender,System.EventArgs e)
{//停止播放
if(this.axMediaPlayer1.FileName.Length>0)
this.axMediaPlayer1.Stop();
{//停止播放
if(this.axMediaPlayer1.FileName.Length>0)
this.axMediaPlayer1.Stop();
else
{
MessageBox.show("请选择歌曲","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
private void button6_Click(object sender,System.EventArgs e)
{//上一首歌曲
if(this .listView1.Items.Count>0)
{
if(this.listView1.SelectedItems.Count>0)
{
int ipos=this.listView1.SelectedItems[0].Index;
if(ipos>0)
{
this.listView1.Items[ipos-1].Selected=true;
string FileName=this.listView1.Items[ipos-1].SubItems[3].Text;
this.axMediaPlayer1.FileName=FileName;
this.axMediaPlayer1.Play();
}
else
{
MessageBox.Show("已经是第一首歌曲!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
}
else
{
MessageBox.Show("请选择歌曲","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
{
MessageBox.show("请选择歌曲","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
private void button6_Click(object sender,System.EventArgs e)
{//上一首歌曲
if(this .listView1.Items.Count>0)
{
if(this.listView1.SelectedItems.Count>0)
{
int ipos=this.listView1.SelectedItems[0].Index;
if(ipos>0)
{
this.listView1.Items[ipos-1].Selected=true;
string FileName=this.listView1.Items[ipos-1].SubItems[3].Text;
this.axMediaPlayer1.FileName=FileName;
this.axMediaPlayer1.Play();
}
else
{
MessageBox.Show("已经是第一首歌曲!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
}
else
{
MessageBox.Show("请选择歌曲","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
![](https://img2018.cnblogs.com/blog/1500011/201811/1500011-20181120213429684-744561621.jpg)