進哥的布拉格

Chin Gooole's Blog

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace dragDrop
{
    
public partial class Form1 : Form
    {
        
public Form1()
        {
            InitializeComponent();
        }

        
private void listBox1_DragDrop(object sender, DragEventArgs e)
        {
            
object obj = e.Data.GetData(DataFormats.FileDrop);

            Array files 
= obj as Array;

            String s 
= "";
            
foreach (object o in files)
            {
                s 
= o as string;
            }
            s 
= s.Remove(0, s.LastIndexOf('\\'+ 1);

            listBox1.Items.Add(s);
        }

        
private void listBox1_DragEnter(object sender, DragEventArgs e)
        {
            
if (e.Data.GetDataPresent(DataFormats.FileDrop))
                e.Effect 
= DragDropEffects.Copy;
        }
    }
}
posted on 2008-10-22 01:12  進哥  阅读(145)  评论(0编辑  收藏  举报