C# 文件拖放到此程序的操作
来源:百度知道 编辑:UC知道 时间:2024/06/08 09:34:56
this.textBox1.AllowDrop = true;
this.textBox1.Multiline = true;
private void textBox1_DragDrop(object sender, DragEventArgs e)
{
Array aryFiles = ((System.Array)e.Data.GetData(DataFormats.FileDrop));
for(int i = 0;i<aryFiles.Length;i++)
{
this.textBox1.AppendText(aryFiles.GetValue(i).ToString() + Environment.NewLine);
}
}
private void textBox1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effect = DragDropEffects.Link;
else e.Effect = DragDropEffects.None;
}
private void Form1_DragDrop(object sender, DragEventArgs e)
{
string path = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
MessageBox.Show(path);