将控件的属性AllowDrop设置为true,然后添加DragDrop、DragEnter时间处理函数
private void FormMain_DragEnter(object sender, DragEventArgs e)
{
if(e.Data.GetDataPresent(DataFormats.FileDrop))
{
txtSourceBin.Text = "";
txtGenerateBin.Text = "";
e.Effect = DragDropEffects.Link;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void FormMain_DragDrop(object sender, DragEventArgs e)
{
string filePath= ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
if (filePath.Substring(filePath.LastIndexOf(".")).ToLower() == ".bin")
{
txtSourceBin.Text = filePath;
SetDefaultFileName(txtSourceBin.Text);
}
}