-5

我正在使用 c# 制作 mp3 播放器,但我遇到了这个错误

“不能将类型'string'隐式转换为'string[]”。

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }
    string[] f, p;

    private void button1_Click(object sender, EventArgs e)
    {
        OpenFileDialog open = new OpenFileDialog();
        if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {

            f = openFileDialog1.SafeFileName;
            p = openFileDialog1.FileName;
            for (int i = 0; i < f.Length; i++)
            {
                listBox1.Items.Add(f[i]);

            }
            foreach(string d in open.FileNames)
            { 
                listBox1.Items.Add(d);
            }
        }
    }

    private void listBox1_MouseDoubleClick(object sender, MouseEventArgs e)
    {
        axWindowsMediaPlayer1.URL = p[listBox1.SelectedIndex];

    }
}

}

4

2 回答 2

6

看起来您正在尝试处理打开多个文件的用户。在这种情况下,请使用FileDialog.FileNames而不是FileName. 同上SafeFileNames

(我也强烈建议重命名变量,使它们的名称有意义——f并且p不要告诉你任何关于它们的信息。)

于 2013-11-01T14:43:21.087 回答
2
 change your code with following code :---

 f = openFileDialog1.SafeFileNames;
 p = openFileDialog1.FileNames;
于 2013-11-01T14:55:39.500 回答