| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 751 人关注过本帖
标题:这是把别人写的代码稍微修改了一下,但是不能使用
只看楼主 加入收藏
gudd123
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2012-6-13
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:2 
这是把别人写的代码稍微修改了一下,但是不能使用
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using

namespace mplayer
{
    public partial class mplayer: Form

    {
       private string []playlist=new string[10000];
        private int num;
   
        public void AddFile(string path)
      
        { if(num<10000)
           {
            num++;
            playlist[num]=path;

            }
        }

        private void DelFile(int selectnum)
        {
          for(int i=selectnum;i<num-1;i++)
            {
              playlist[i]=playlist[i+1];
               
             }
          num--;
        }
        private void AddFiles(string path, ListBox listBox1)
        {  
            DirectoryInfo dir=new DirectoryInfo(path);
            foreach (FileInfo f in dir.GetFiles("*.mp3"))
            {
                AddFile(f.FullName);

                string strTmp = Convert.ToString(num);

                for (int i = 1; i <= 5 - strTmp.Length; i++)
                {
                    strTmp += ' ';
                    strTmp += "--" + f.Name;
                    this.listBox1.Items.Add(strTmp);
                }

            }
               foreach (DirectoryInfo f in dir.GetDirectories())
               {
                AddFiles(f.FullName,listBox1);
               }
            }
        
            public void PlaySong(int selectnum)
              {
                MediaPlayer1.URL=playlist[selectnum];
              }

           public mplayer()
          {
               InitializeComponent();
          }
                                                  
   

        private void button1_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = "f:\\";   //设置初始打开路径
            folderBrowserDialog1.ShowNewFolderButton = true;
            folderBrowserDialog1.Description = "请选择音乐文件目录:"; // 显示新建文件夹按钮
            folderBrowserDialog1.ShowDialog();
            AddFiles(folderBrowserDialog1.SelectedPath, listBox1);    //调用AddFiles方法
        }

        private void mplayer_Load(object sender, EventArgs e)
        {
            listBox1.Items.CopyTo(playlist, 0);
            num = 0;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "*.mp3|*.mp3";
            if (this.openFileDialog1.ShowDialog() == DialogResult.OK)   //调用打开文件对话框
            {
                string path = this.openFileDialog1.FileName;
                FileInfo f = new FileInfo(path);
                AddFile(f.FullName);
                string strTmp = Convert.ToString(num);
                for (int i = 1; i <= 5 - strTmp.Length; i++)
                    strTmp += ' ';
                strTmp += "--" + f.Name;
                this.listBox1.Items.Add(strTmp);                    //在列表框中显示添加的歌曲
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            int SelectOne;
            if (listBox1.SelectedIndex < 0)
                SelectOne = 1;
            else
                SelectOne = listBox1.SelectedIndex + 1;

            if (listBox1.Items.Count < 0)
                listBox1.SelectedIndex = 0;
            PlaySong(SelectOne);                             //播放当前选择歌曲

        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex >= 0)
            {
                DelFile(listBox1.SelectedIndex + 1);                //调用DelFile方法
                listBox1.Items.RemoveAt(listBox1.SelectedIndex);
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            MediaPlayer1.URL = "";
        }

        private void button6_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}         
      
搜索更多相关主题的帖子: private void 10000 public 
2012-06-13 17:09
yms123
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
收藏
得分:20 
这个是WinForm的代码不是,帮LZ转到WinFrom
2012-06-14 09:55
gudd123
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2012-6-13
收藏
得分:0 
哦,好的,多谢提醒,呵呵
2012-06-14 15:02
快速回复:这是把别人写的代码稍微修改了一下,但是不能使用
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.044096 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved