c# OnDropFile
c# OnDropFile
Form에서 AllowDrop=true로 변경하고,DragDrop, DragEnter 이벤트 핸들러 추가,
private void Form1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.All;
} else
{
//String[] strGetFormats = e.Data.GetFormats();
//e.Effect = DragDropEffects.None;
}
}
private void Form1_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
// Assign the file names to a string array, in
// case the user has selected multiple files.
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
try
{
int i; for (i = 0; i < files.Length; i++)
{
OnDropFile(files[i]);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
}
}