Programing/C#
WindowForm에서 File DragAndDrop
즐거운 개발자
2012. 5. 16. 17:10
반응형
private void MainForm_DragDrop(object sender, DragEventArgs e)
{
// transfer the filenames to a string array
// (yes, everything to the left of the "=" can be put in the
// foreach loop in place of "files", but this is easier to understand.)
if (e.Data.GetDataPresent(DataFormats.FileDrop, false) == true)
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
foreach (string item in files)
{
OpenFile(item);
}
}
}
private void MainForm_DragEnter(object sender, DragEventArgs e)
{
// make sure they're actually dropping files (not text or anything else)
if (e.Data.GetDataPresent(DataFormats.FileDrop, false) == true)
// allow them to continue
// (without this, the cursor stays a "NO" symbol
e.Effect = DragDropEffects.All;
}