清风的blog 优然探索

未命名文章

设置Form的AllowDrop为true

        private void Form1_DragDrop(object sender, DragEventArgs e)
        {
            String[] fileNames = (String[])e.Data.GetData(DataFormats.FileDrop);
            int j = listBox1.Items.Count + 1;
            for (int i = 0; i < fileNames.Length; i++)
            {
                listBox1.Items.Add(String.Format("{0:D3} ", i + j) + fileNames[i]);
            }
            //string path = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
            //MessageBox.Show(path);  

        
        }

        private void Form1_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetData(DataFormats.FileDrop) != null)
            {
                e.Effect = DragDropEffects.Copy;
            }
            //if (e.Data.GetDataPresent(DataFormats.FileDrop))
            //    e.Effect = DragDropEffects.Link;
            //else e.Effect = DragDropEffects.None;

        }

2011年1月11日 | 发布:admin | 分类:技术文章 | 评论:0

发表留言: