تو این پروژه میبینیم که چطور میشه با درگ کردن و رها کردن یه تصویر تو فرم میشه اون رو تو picturebox نمایش داد.
برای اینکار کافیه اول خاصیت AlowDrop رو True کرده و از کد زیر استفاده کنید:
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.All;
}
private void Form1_DragDrop(object sender, DragEventArgs e)
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
foreach (string file in files)
{
pic.Image = Image.FromFile(file);
}
}
}
}
مثال هم پیوست شد.