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

C# Winform 拖放文件

C#1年前 (2024-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# 中实现类似于 Windows 资源管理器的“名称”排序方式

要在 C# 中实现类似于 Windows 资源管理器的“名称”排序方式,你需要考虑以下几点:1. 不...

C# Browsable(bool)

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

C# ref 和out

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

C# Graphics文本抗锯齿

g.TextRenderingHint = TextRenderingHint....

C# i++和++i的区别

核心区别操作顺序            ...

C# 比较两个Image对象是否相同

方法思路基础检查:先检查空引用和图像尺寸像素格式验证:确保两个图像的像素格式相同内存锁定:使用Loc...