当年上学时候写的一个很简单的东西,拖动图片到程序中自动重命名保存到指定位置,
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
using System.Net;
using System.Threading;
namespace DragPhoto
{
///
///
/// 关于: 这个是拖动本地图片,批量操作或者多线程下载来自网络的图片的小工具
///来由:保存空间图片很费劲,比较麻烦,直接拖拽图片比较好
/// 作者:intbird;网易邮箱:intbird@163.com ; QQ652768664
///source_time:2013-3-12;
///
///
public partial classForm1 : Form
{
private FolderBrowserDialog dia = newFolderBrowserDialog();
//用于存储文件的键值对,键:文件全路径;值:文件地址;
private Dictionary dic = new Dictionary();
//获取保存文件的文件夹地址
private String savePath = null;
private String localPath = null;
//下载文件名
private string DragFile = "";
//获取的文件信息
private FileInfo file = null;
//报告异常的 委托方法
private delegate void myAdd(Object ee);
private myAdd myadd;
//下载计数,用于浏览图片
private static int downCount = 0;
public Form1()
{
InitializeComponent();
}
private void init()
{
dic.Clear();
lsbDragtarget.Items.Clear();
downCount= 0;
lsbDragtarget.Items.Clear();
dia = newFolderBrowserDialog();
}
///
/// 将选择的文件夹显示在该项下面
///
///
///
private void savechooserMenuItem_Click(objectsender, EventArgs e)
{
init();
if(dia.ShowDialog() == DialogResult.OK)
{
ToolStripMenuItemshowPathItem =
new ToolStripMenuItem("保存位置在{ " +dia.SelectedPath + "点击打开目录 }");
savePath =dia.SelectedPath;
labResult.Text = "文件保存位置 :" +savePath;
saveMenu.DropDownItems.Add(showPathItem);
showPathItem.Click += newEventHandler(openDirectory);
}
dia =null;
}
#region 拖放文件操作
///
/// 当拖动文件进入列表框时,将收到的数据存放入字典,将字典的值填充列表项
///
///
///
private void lsbSource_DragEnter(object sender,DragEventArgs e)
{
//BackgroundWorker work = new BackgroundWorker();
//work.DoWork += new DoWorkEventHandler(Dowork);
getDragFile(e);