如何将外部文件拖入到程序中?
using System;
using System.Windows.Forms;namespace WindowsApplication41
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.AllowDrop = true;
}
public void InvokeDragFile(string[] files)
{
//处理拖入文件,比如加入列表
this.listBox1.Items.AddRange(files);
}
private void Form1_DragDrop(object sender, DragEventArgs e)
{
object obj= e.Data.GetData(DataFormats.FileDrop);
if (obj != null)
{
string[] arr = (string[])obj;
if (arr != null)
{
InvokeDragFile(arr);
}
}
}
private void Form1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effect = DragDropEffects.Copy;
}
}
}--------------------------------------------------------
很多人发蛋贴攒分,我也发发,但是有1分,发了也不能白发,我会随口说个技术基础点,不只局限于代码。
高手可以忽略本贴
using System;
using System.Windows.Forms;namespace WindowsApplication41
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.AllowDrop = true;
}
public void InvokeDragFile(string[] files)
{
//处理拖入文件,比如加入列表
this.listBox1.Items.AddRange(files);
}
private void Form1_DragDrop(object sender, DragEventArgs e)
{
object obj= e.Data.GetData(DataFormats.FileDrop);
if (obj != null)
{
string[] arr = (string[])obj;
if (arr != null)
{
InvokeDragFile(arr);
}
}
}
private void Form1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effect = DragDropEffects.Copy;
}
}
}--------------------------------------------------------
很多人发蛋贴攒分,我也发发,但是有1分,发了也不能白发,我会随口说个技术基础点,不只局限于代码。
高手可以忽略本贴
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货