【C#】【桌面应用开发】拖拽文件到文本框获得所拖拽文件的路径
步骤1:设置文本框属性
设置文本框属性,将属性AllowDrop改为True
使其允许拖拽文件
步骤2:
在控件事件管理中双击DragEnter,添加事件
private void Form_settings_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effect = DragDropEffects.Link;
else e.Effect = DragDropEffects.None;
}
步骤3:
在控件事件管理中双击DragDrop,添加事件
private void Form_settings_DragDrop(object sender, DragEventArgs e)
{
string path = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
textBox_ffmepg_path.Text = path;
}
结果展示
版 权 声 明
作者:萌狼蓝天
QQ:3447902411(仅限技术交流,添加请说明方向)
转载请注明原文链接:https://www.cnblogs.com/mllt/p/CSHAP_DROPTOTEXT.html