拖放显示带线的圆圈
Drag & Drop Shows Circle With Line Through It
我想我的设置是准确的,但是每当我尝试将文件拖到我的表单上时,它只会显示一个带有一条线的圆圈。哪个部分设置不正确?
private void Form1(object sender, EventArgs e)
{
this.AllowDrop = true;
this.DragDrop += new DragEventHandler(Form1_DragDrop);
this.DragEnter += new DragEventHandler(Form1_DragEnter);
}
private void Form1_DragDrop(object sender, DragEventArgs e)
{
if (!e.Data.GetDataPresent(DataFormats.FileDrop)) return;
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
foreach (var file in files)
{
var ext = Path.GetExtension(file);
if (ext.Equals(".xlsx", StringComparison.CurrentCultureIgnoreCase))
{
e.Effect = DragDropEffects.Copy;
MessageBox.Show(sender.ToString());
return;
}
else { MessageBox.Show("This filetype is not allowed");
}
}
private void Form1_DragEnter(object sender, DragEventArgs e)
{
if (!e.Data.GetDataPresent(DataFormats.FileDrop)) return;
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
foreach (var file in files)
{
var ext = Path.GetExtension(file);
if (ext.Equals(".xlsx", StringComparison.CurrentCultureIgnoreCase))
{
e.Effect = DragDropEffects.Copy;
MessageBox.Show(sender.ToString());
return;
}
else { MessageBox.Show("This filetype is not allowed");
}
}
编辑代码
这对我有用...
public partial class Form1 : Form
{
public Form1()
{
this.InitializeComponent();
this.AllowDrop = true;
this.DragDrop += new DragEventHandler(Form1_DragDrop);
this.DragEnter += new DragEventHandler(Form1_DragEnter);
}
private void Form1_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
foreach (var file in files)
{
MessageBox.Show(file);
}
}
}
private void Form1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.Copy;
}
}
}
从 windows 资源管理器/我的桌面等中删除任何文件会显示一个包含路径和文件名的消息框
我想我的设置是准确的,但是每当我尝试将文件拖到我的表单上时,它只会显示一个带有一条线的圆圈。哪个部分设置不正确?
private void Form1(object sender, EventArgs e)
{
this.AllowDrop = true;
this.DragDrop += new DragEventHandler(Form1_DragDrop);
this.DragEnter += new DragEventHandler(Form1_DragEnter);
}
private void Form1_DragDrop(object sender, DragEventArgs e)
{
if (!e.Data.GetDataPresent(DataFormats.FileDrop)) return;
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
foreach (var file in files)
{
var ext = Path.GetExtension(file);
if (ext.Equals(".xlsx", StringComparison.CurrentCultureIgnoreCase))
{
e.Effect = DragDropEffects.Copy;
MessageBox.Show(sender.ToString());
return;
}
else { MessageBox.Show("This filetype is not allowed");
}
}
private void Form1_DragEnter(object sender, DragEventArgs e)
{
if (!e.Data.GetDataPresent(DataFormats.FileDrop)) return;
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
foreach (var file in files)
{
var ext = Path.GetExtension(file);
if (ext.Equals(".xlsx", StringComparison.CurrentCultureIgnoreCase))
{
e.Effect = DragDropEffects.Copy;
MessageBox.Show(sender.ToString());
return;
}
else { MessageBox.Show("This filetype is not allowed");
}
}
编辑代码
这对我有用...
public partial class Form1 : Form
{
public Form1()
{
this.InitializeComponent();
this.AllowDrop = true;
this.DragDrop += new DragEventHandler(Form1_DragDrop);
this.DragEnter += new DragEventHandler(Form1_DragEnter);
}
private void Form1_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
foreach (var file in files)
{
MessageBox.Show(file);
}
}
}
private void Form1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.Copy;
}
}
}
从 windows 资源管理器/我的桌面等中删除任何文件会显示一个包含路径和文件名的消息框