C# winform文件拖放操作

winform实现拖放功能需要先对控件的AllowDrog属性设置为true

 在控件的DragEnter事件捕获拖放的文件列表

定义全局变量string[] filesPath=null;

filesPath=(string[])e.Data.GetData(DataFormats.FileDrop);

//文件拖放完成时执行的方法

void DrogComplete(Control ctrl)

{

Rectangle rect = new Rectangle(PointToScreen(ctrl.Location), ctrl.Size);
if (rect.Contains(MousePosition))
{
//遍历拖放的文件
foreach (string item in filesPath)
{
//执行对拖放的文件的操作
}
}

}

posted on 2015-01-30 14:13  不得不写  阅读(308)  评论(0编辑  收藏  举报