当前位置:首页 > 开发 > C# > 正文内容

C# Winform 拖放文件

C#6个月前 (12-23)
private void Form1_Load(object sender, EventArgs e)
{
    this.AllowDrop = true;
    this.DragEnter += Form_DragEnter;
    this.DragDrop += Form0_DragDrop;
}

private void Form_DragEnter(object sender, DragEventArgs e)
{
    if (e.Data.GetDataPresent(DataFormats.FileDrop))
    {
		e.Effect = DragDropEffects.Copy;
    }
    else
    {
		e.Effect = DragDropEffects.None;
    }
}
private void Form0_DragDrop(object sender, DragEventArgs e)
{
    string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
    foreach (string file in files)
    {
		Console.WriteLine(file);
    }
}


转载请注明出处。

本文链接:http://pythonopen.com/?id=1625

相关文章

C# for,while,do while,switch

for    #region for for ...

C# 跳出foreach循环

在 C# 中,如果你想在 foreach 循环内部提前跳出当前这一轮循环,继续执行下一轮循环,可以使...

C# Browsable(bool)

在编程中(比如常见的 C# 语言在开发 Windows Forms 等应用程序时),Browsabl...

C# BackgroundWorker,在DoWork里更新控件内容

一般情况下不可以直接在BackgroundWorker的DoWork事件中更新 UI 控件在Back...

C# ref 和out

ref关键字概念:ref是 C# 中的一个关键字,用于按引用传递参数。当在方法调用中使用ref关键字...