www.pudn.com > MyFindMP3.rar > Form1.cs


using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 
using System.IO; 
using System.Threading; 
 
namespace WindowsFormsApplication1 
{ 
    public partial class Form1 : Form 
    { 
        public Form1() 
        { 
            InitializeComponent(); 
        } 
        int i; 
        Thread myThread; 
 
 
        private void Form1_Load(object sender, EventArgs e) 
        { 
            this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components); 
            notifyIcon1.Icon = new Icon("icon.ico");//指定一个图标    
            notifyIcon1.Visible = false; 
            notifyIcon1.Click += new System.EventHandler(this.notifyIcon1_Click); 
            this.SizeChanged += new System.EventHandler(this.Form1_SizeChanged);   
        } 
        private void GetAllDirectories(string rootPath) 
        { 
            try 
            { 
                string[] subPaths = Directory.GetDirectories(rootPath); 
                foreach (string path in subPaths) 
                { 
                    GetAllDirectories(path); 
                } 
                string[] files = Directory.GetFiles(rootPath); 
                foreach (string file in files) 
                { 
                    FileInfo fi = new FileInfo(file); 
                    SerchNow.Text = fi.FullName; 
                    string exname = file.Substring(file.LastIndexOf(".") + 1);  
 
                    //if (".mp3".LastIndexOf(file.Substring(file.LastIndexOf(".") + 1)) > -1) 
                    if( String.Compare(exname,"mp3") ==0) 
                    { 
                        //FileInfo fi = new FileInfo(file); 
                        //SerchNow.Text = fi.FullName; 
                        ListViewItem List = listView1.Items.Add(Convert.ToString(++i)); 
                        List.SubItems.Add(fi.FullName); 
                        List.SubItems.Add(Convert.ToString(fi.Length / 1024.0 / 1024.0).Remove(4) + "MB"); 
                       
                    } 
                } 
 
            } 
            catch 
            { 
            } 
        } 
 
        private void SearchMp3() 
        {  
           if(labelpath.Text != "本地磁盘") 
            { 
                GetAllDirectories(labelpath.Text); 
            } 
            else 
            { 
                string[] drvs = Environment.GetLogicalDrives(); 
                for(int j=0;j -1) 
                    { 
                        FileInfo fi = new FileInfo(mymp3path); 
                        SerchNow.Text = fi.FullName; 
                        string exname = mymp3path.Substring(mymp3path.LastIndexOf(".") + 1); 
                        ListViewItem List = listView2.Items.Add(Convert.ToString(++num)); 
                        List.SubItems.Add(fi.FullName); 
                        List.SubItems.Add(Convert.ToString(fi.Length / 1024.0 / 1024.0).Remove(4) + "MB"); 
                    } 
                } 
 
                if (num == 0) 
                { 
                    MessageBox.Show("对不起,没有你要听的歌曲!"); 
 
                } 
            } 
            catch 
            {  
            } 
             
        } 
 
        private void SerchNow_Click(object sender, EventArgs e) 
        { 
 
        } 
 
        private void listView2_SelectedIndexChanged(object sender, EventArgs e) 
        { 
            ListView.SelectedListViewItemCollection MyChooseMP3 = listView2.SelectedItems; 
            foreach (ListViewItem item in MyChooseMP3) 
            { 
                SerchNow.Text = item.SubItems[1].Text; 
            } 
        } 
 
        private void listView2_Click(object sender, EventArgs e) 
        { 
            if (SerchNow.Text != "") 
            { 
                this.axWindowsMediaPlayer1.URL = SerchNow.Text; 
                this.axWindowsMediaPlayer1.Ctlcontrols.play(); 
            } 
            else 
            { 
                SerchNow.Text = "请单击选择要播放的音乐!"; 
            } 
        } 
 
        private void label1_Click(object sender, EventArgs e) 
        { 
 
        } 
 
        private void MyMP3Name_TextChanged(object sender, EventArgs e) 
        { 
 
        } 
 
        private void label2_Click(object sender, EventArgs e) 
        { 
 
        } 
 
        private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e) 
        { 
 
        } 
 
        private void notifyIcon1_Click(object sender, EventArgs e) 
        { 
            if (this.WindowState == FormWindowState.Minimized) 
                this.WindowState = FormWindowState.Normal; 
            this.Activate(); 
            this.notifyIcon1.Visible = false; 
            this.ShowInTaskbar = true;   
        } 
 
        private void Form1_SizeChanged(object sender, EventArgs e) 
        { 
            if (this.WindowState == FormWindowState.Minimized)//最小化    
            { 
                this.ShowInTaskbar = false; 
                this.notifyIcon1.Visible = true; 
            }    
        } 
 
         
 
         
 
        
        
 
        
    } 
}