C# 鼠标拖动有关问题
C# 鼠标拖动问题
在TextBox上实现了文件的拖拽和路径的获取源代码如下:
但我想问的是能不能实现同时拖动多个文件到TextBox框中,并获取每个文件的路径,我记得有的应用程序是能这样做的,但不知使用C# winform怎么实现???
------解决思路----------------------
string path = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
本来就是拖进来了多个,但你却只处理了一个
------解决思路----------------------
在TextBox上实现了文件的拖拽和路径的获取源代码如下:
private void Form1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effect = DragDropEffects.Link; //重要代码:表明是链接类型的数据,比如文件路径
else e.Effect = DragDropEffects.None;
}
private void Form1_DragDrop(object sender, DragEventArgs e)
{
string path = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
MessageBox.Show(path);
}
但我想问的是能不能实现同时拖动多个文件到TextBox框中,并获取每个文件的路径,我记得有的应用程序是能这样做的,但不知使用C# winform怎么实现???
------解决思路----------------------
string path = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
本来就是拖进来了多个,但你却只处理了一个
var a = ((System.Array)e.Data.GetData(DataFormats.FileDrop));
for(int i=0; i<a.Length; i++) {
MessageBox.Show(a.GetValue(i).ToString());
}
------解决思路----------------------
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
for (int i = 0; i < files.Length; i++)
{
}