c#怎样实现进程间的拖放操作 c#怎样实现进程间的拖放操作比如:在windows资源管理器中,选择几个文件,拖放到自己的程序中,把文件路径添加在程序的ListBox里 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 ListBox可以实现这个功能,主要就是添加DragEnter,Drop事件。DrapEnter做拖放准备,Drop事件进行数据处理。不管是WPF还是Windows Forms的ListBox操作都差不多一样,下面的参考代码是WPF的。(注Windows Forms的ListBox要修改AllowDrop为true)参考代码: private void ListBox_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop, false) == true) e.Effects = DragDropEffects.All; } private void ListBox_Drop(object sender, DragEventArgs e) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); foreach (string file in files) { listBox1.Items.Add(file); } } listbox拖放private void listBox_DragDrop(object sender, DragEventArgs e) { ListBox destListBox = sender as ListBox; if (e.Data.GetDataPresent(typeof(ListBox))) { ListBox srcListBox = e.Data.GetData(typeof(ListBox)) as ListBox; destListBox.Items.Add(srcListBox.SelectedItem); srcListBox.Items.Remove(srcListBox.SelectedItem); } } private void listBox_DragEnter(object sender, DragEventArgs e) { e.Effect = e.AllowedEffect; } 如果下载整个文件夹,并更换原来的文件 请各位看下我的代码,jQuery的,这个问题简直能把人折腾死 【求教】这个程序改成FOR循环应该怎么改(障碍是不会将变量溶入名字中) c#如何读取智能手机的手机号码 读取xml时提示"未将对象引用设置到对象的实例",痛苦啊,搞了很久了! 请教个人仁兄,如何学C# 关于OleDbConnection的问题 “@userid”标量问题》? 我安装VS.NET2003(共三张盘)时,提示插入VS.NET系统必备光盘,是第几张盘? 引用自定义控件时出现 "未将对象引用设置到对象的实例" C# 界面显示问题 .net线程
private void ListBox_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop, false) == true)
e.Effects = DragDropEffects.All;
} private void ListBox_Drop(object sender, DragEventArgs e)
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
foreach (string file in files)
{
listBox1.Items.Add(file);
}
}
private void listBox_DragDrop(object sender, DragEventArgs e)
{
ListBox destListBox = sender as ListBox;
if (e.Data.GetDataPresent(typeof(ListBox)))
{
ListBox srcListBox = e.Data.GetData(typeof(ListBox)) as ListBox;
destListBox.Items.Add(srcListBox.SelectedItem);
srcListBox.Items.Remove(srcListBox.SelectedItem);
}
} private void listBox_DragEnter(object sender, DragEventArgs e)
{
e.Effect = e.AllowedEffect;
}