2012-07-31 45 views
1

當前我正在加載button.But圖像,但現在我必須拖動圖像從文件夾運行時的圖片框。我們如何實現這一點?如何在運行時將文件夾中的圖像拖動到窗體上?

+1

也許這些鏈接可以幫助您:[在Windows窗體中執行拖放操作](http://msdn.microsoft.com/zh-cn/library/aa984430(v = vs.71)。 aspx),[如何將文件拖放到ac#應用程序中?](http://stackoverflow.com/questions/68598/how-do-i-drag-and-drop-files-into-ac-sharp-應用) – Schaliasos 2012-07-31 09:02:45

回答

3

ok。下面的代碼工作正常。

private void pictureBox1_DragEnter(object sender, DragEventArgs e) 
    { 

     try 
     { 
      pictureBox1.Image = null; 
      string[] filename = (string[])e.Data.GetData(DataFormats.FileDrop); 
      pictureBox1.Image = Image.FromFile(filename[0]); 
     } 
     catch (Exception expr) 
     { } 
    } 
相關問題