c# - 拖放不起作用

标签 c# .net wcf

我有一个使用 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/

相关文章:

c# - PropertyInfo.SetValue 无法将字符串转换为 Decimal

c# - ASP.NET 成员更改密码不起作用

c# - Unity3D 的 OpenCV dll 调用导致 FPS 下降

c# - TLB 到部署时没有 Regsrv32 的托管 .NET 程序集

c# - Parallel.ForEach() 是否在执行后立即销毁线程?

c# - 在 JSON 反序列化期间将 int 转换为 bool

c# - 找不到 ObjectDataSource 的 TypeName 属性中指定的类型

javascript - 预检响应具有无效的 HTTP 状态代码 405

.net - WCF 中密码不能包含英镑?

c# - 如何使用从重叠的 WSDL 生成的 WCF 代理来制作 DRY 代码