C# listbox支持拖放文件

        private void Form1_DragDrop(object sender, DragEventArgs e)

        {

            string path = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();

            listBox1.Items.Add(path);//ᅬᅯᅧ홰ᅣᄐ￾ᄐ￐ᅣ﾿ᅡᄐ



        }

private void Form1_DragEnter(object sender, DragEventArgs e)

        {

            if (e.Data.GetDataPresent(DataFormats.FileDrop))

                e.Effect = DragDropEffects.Link;

            else

               e.Effect = DragDropEffects.None;

        }

private void button1_Click(object sender, EventArgs e)

        {



            if (listBox1.Items.Count == 0)

            {

                MessageBox.Show("no file name ");

            }

            else

            {

                func_SearchFiles(sender, e);//取得文件名

            }

        }

  

你可能感兴趣的:(listbox)