Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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;

        }
Posted
Updated 10-Dec-18 2:38am
v3

I solved with these codes:

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900