我尝试将图片从图片框拖放到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());
}
}
答案 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());
}
}