C# textbox拖入路径

private void txt_file_DragDrop(object sender, DragEventArgs e)
{
((TextBox)sender).Text = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();

string strFileName = this.txt_file.Text.Trim();
if (strFileName == "") return;

if (strFileName.Substring(strFileName.Length - 4, 4) != ".csv"
&& strFileName.Substring(strFileName.Length - 4, 4) != ".CSV")
{
this.txt_file.Text = strFileName + ".csv";
}
}

private void txt_file_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.Link;
}
else
{
e.Effect = DragDropEffects.None;
}
}

相关文章