2014-09-30 51 views
-2

我嘗試將圖片從圖片框拖放到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()); 
    } 
} 
+0

你有沒有調試您的應用程序? – 2014-09-30 13:24:06

+0

你能詳細說明你的代碼「不起作用」嗎?你在期待什麼,究竟發生了什麼?如果您遇到異常,請發佈它發生的行和異常詳細信息。 – gunr2171 2014-09-30 13:24:15

+0

我沒有任何異常。我寫到,直到pic.Image.Save(「tmp.jpg」);行都沒事。我真的不知道跆拳道發生了,它只是應該工作,而不是。 – santipianis 2014-09-30 13:50:19

回答

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()); 
    } 
} 
相關問題