我有一个使用 WCF 创建的上传/下载 Web 服务。我使用 c Sharp 作为语言。
我在我的文本框中启用了允许拖放功能,该文本框接受要拖入其中的项目,但它不允许我这样做,我仍然发现没有任何迹象悬停在它上面。
我有什么遗漏的吗? 仅供引用,我使用完全相同的代码制作了另一个程序,并且我能够毫无问题地拖放项目。
private void FileTextBox_DragEnter(object sender, DragEventArgs e)
{
//Makes sure that the user is dropping a file, not text
if (e.Data.GetDataPresent(DataFormats.FileDrop, false) == true)
//Allows them to continue
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
}
private void FileTextBox_DragDrop(object sender, DragEventArgs e)
{
String[] files = (String[])e.Data.GetData(DataFormats.FileDrop);
foreach (string file in files)
{
FileTextBox.Text = file.ToString();
}
}
最佳答案
这些并不是您需要的唯一代码。你将需要:
FileTextBox.AllowDrop = true;
FileTextBox.DragEnter += new DragEventHandler (FileTextBox_DragEnter);
FileTextBox.DragDrop += new DragEventHandler (FileTextBox_DragDrop);
当然,如果您使用的是 IDE,则可以通过在表单设计器中分配处理程序来实现此目的。
关于c# - 拖放不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5413058/