按钮文件丢失不起作用 [英] Button file drop not working

查看:130
本文介绍了按钮文件丢失不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这些代码不适用于按钮文件下降



我尝试过:



These codes not work for button file drop

What I have tried:

  public Form1()
        {
            InitializeComponent();
            button1.AllowDrop = true;
        }

private void button1_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = e.Data.GetDataPresent("FileNameW") ? DragDropEffects.Move : DragDropEffects.None;
            string s = (string)e.Data.GetData(DataFormats.FileDrop, false);
            button1.Text = s;

        }

推荐答案

请参见此处的示例:演练:在Windows窗体中执行拖放操作Microsoft Docs [ ^ ]
See example here: Walkthrough: Performing a Drag-and-Drop Operation in Windows Forms | Microsoft Docs[^]


我用这些代码解决了:



I solved with these codes:

string[] file = (string[])e.Data.GetData(DataFormats.FileDrop);
            if (file != null && file.Length != 0)
            {
                button1.Text = file[0];
            }


这篇关于按钮文件丢失不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆