和源码程序一样,源码能拖放数据,我的不能?请老师指教。谢谢!
源码程序为:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
namespace AllowDropFile
{
public partial class Frm_Main : Form
{
public Frm_Main()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.AllowDrop = true;
}
private void Form1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); //获取拖入文件的基本信息
for (int i = 0; i < files.Length; i++) //拖放入窗体的文件的文件名加入ListBox
{
listBox1.Items.Add(files[i]); //添加文件的路径
}
}
}
}
}
运行后:
我的程序为:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AllowDropFile
{
public partial class Frm_Main : Form
{
public Frm_Main()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.AllowDrop = true;
}
private void Form1_DragDrop(object sender, DragEventArgs e)
{
if(e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
for(int i=0;i<files.Length;i++)
{
listBox1.Items.Add(files[i]);
}
}
}
}
}
运行后: