OpenFileDialog opfPlayer = new OpenFileDialog();
                DialogResult result = opfPlayer.ShowDialog();
                if (result == DialogResult.OK)
                {
                    string file = opfPlayer.FileName;
                    //被播放文件地址
                    axWindowsMediaPlayer1.URL = file;
                    
                }

解决方案 »

  1.   

                   DialogResult result = opfPlayer.ShowDialog();//这个已打开一次(这个可以去掉)
                   
            改为        if (opfPlayer.ShowDialog() == DialogResult.OK)//这个又打开一次
                    {
                        string file = opfPlayer.FileName;
                        //被播放文件地址
                        axWindowsMediaPlayer1.URL = file;
                        
                    }
      

  2.   


    OpenFileDialog opfPlayer = new OpenFileDialog();
    //DialogResult result = opfPlayer.ShowDialog();
    if (opfPlayer.ShowDialog() == DialogResult.OK)
    {
         string file = opfPlayer.FileName;
         //被播放文件地址
          axWindowsMediaPlayer1.URL = file;
        //把文件名称添加到播放列表中
         listForm.addFile(file);  

    改为它之后还是不行,依旧打开两次
      

  3.   

    不可能的,除你前面已有相同的opfPlayer实例
      

  4.   

    OpenFileDialog opfPlayer = new OpenFileDialog();
                //DialogResult result = opfPlayer.ShowDialog();
                if (opfPlayer.ShowDialog() == DialogResult.OK)
                {
                    string file = opfPlayer.FileName;
                    //被播放文件地址
                    //axWindowsMediaPlayer1.URL = file;
                    //把文件名称添加到播放列表中
                    //listForm.addFile(file);
                } 
    用上面的代码测试,只是打开一次的亚
      

  5.   

    谢谢,我用断点调试了,函数执行两次,原因是,我是双击组件,我在系统自动为我生成代码中添加的代码,不过之前我又多写了一句 public MainForm()
            {
                MainForm mainForm = this;
                listForm = new ListForm(ref mainForm);
                InitializeComponent();
                //选择文件事件
                //buttonOpenFile.Click += new EventHandler(buttonOpenFile_Click);
            }
    我把那句注释掉就好了,谢谢大家哈