将图片拖放到资源管理器中

时间:2014-09-30 13:21:58

标签: c# picturebox drag explorer

我尝试将图片从图片框拖放到Windows资源管理器,但文件只是不复制。 也许是因为PictureBox在自定义Controller中不起作用? 临时文件保存成功。

private void _picBox_MouseDown(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left)
    {
            var pic = (PictureBox) sender;
            pic.Image.Save(@"tmp.jpg");
            var files = new string[] {@"tmp.jpg"};
            var res = pic.DoDragDrop(new DataObject(DataFormats.FileDrop, files), DragDropEffects.Copy | DragDropEffects.Move);
            MessageBox.Show(res.ToString());
    }
}  

1 个答案:

答案 0 :(得分:0)

仅适用于完整路径

 private void _picBox_MouseDown(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
        var programFullPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
        var programDirectory = System.IO.Path.GetDirectoryName(programFullPath);
        var pic = (PictureBox) sender;
        pic.Image.Save(programDirectory+ @"\tmp.jpg");
        var files = new string[] {programDirectory+ @"\tmp.jpg"};
        var res = pic.DoDragDrop(new DataObject(DataFormats.FileDrop, files), DragDropEffects.Copy | DragDropEffects.Move);
        MessageBox.Show(res.ToString());
    }
 }