展开全部
设置允许拖放,并处理拖入和拖放事件
textBox.AllowDrop = true;
textBox.DragEnter += new DragEventHandler(textBox_DragEnter);
textBox.DragDrop += new DragEventHandler(textBox_DragDrop);
获取文件路径
void textBox_DragDrop(object sender, DragEventArgs e)
{
string path = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
textBox.Text = path;
}
拖入的是文件则响应
void textBox_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effect = DragDropEffects.Link;
else
e.Effect = DragDropEffects.None;
}
textBox.AllowDrop = true;
textBox.DragEnter += new DragEventHandler(textBox_DragEnter);
textBox.DragDrop += new DragEventHandler(textBox_DragDrop);
获取文件路径
void textBox_DragDrop(object sender, DragEventArgs e)
{
string path = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
textBox.Text = path;
}
拖入的是文件则响应
void textBox_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effect = DragDropEffects.Link;
else
e.Effect = DragDropEffects.None;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询