将图片拖放到资源管理器



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

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());
    }
}  

它只适用于全路径

 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());
    }
 }

最新更新