-1

我尝试使用 c# 制作媒体播放器,但当我想播放下一首歌曲时出现问题

“指数数组的边界之外。”

private void button2_Click(object sender, EventArgs e)
{
    if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
    {
        files = openFileDialog.SafeFileNames;
        path = openFileDialog.FileNames;

        for (int i = 0; i < files.Length; i++)
        {
            listBox1.Items.Add(files[i]);
        }
    }
}

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    wmp.URL = path[listBox1.SelectedIndex];
}

"Index was outside the bounds of the array."发生错误

wmp.URL = path[listBox1.SelectedIndex];
4

1 回答 1

0
wmp.URL = path[listBox1.SelectedIndex];

这是失败的,因为 listBox1.SelectedIndex 是一个大于路径数组中元素数的数字。您正试图从不存在的数组中拉出一个项目。

于 2013-10-24T05:25:39.983 回答