本文實例講述了winform實現拖動文件到窗體上的方法。分享給大家供大家參考。具體如下:
private void Form5_Load(object sender, EventArgs e)
{
this.AllowDrop=true;
}
private void Form5_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
foreach (string f in files)
{
listBox1.Items.Add(f);
}
}
}