2013-10-24 32 views
-1

我試着用C#,使媒體播放器,我有一個問題,當我要玩下一首歌曲指數數組的邊界之外的axWindowsMediaPlayer1

「索引數組的範圍之外。」

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]; 

回答

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

這是失敗,因爲listBox1.SelectedIndex比路徑數組中元素的數目大的數目。您正試圖從不存在的數組中拉出項目。

相關問題