1
votes

AllowDrop is enabled on both Form1 and textBox1. The events are enabled and start when DragDrop and DragEnter are performed. I've already tried rearranging the code so that textBox1_DragEnter is located before textBox1_DragDrop, but that doesn't work. What is wrong with this code?

private void textBox1_DragDrop(object sender, DragEventArgs e)
{
    FileInfo fi = new FileInfo((string)e.Data.GetData(DataFormats.FileDrop));
    byte[] ba = Encoding.Default.GetBytes(fi.OpenText().ToString().ToCharArray());
    textBox1.Text = ba.ToString();
}

private void textBox1_DragEnter(object sender, DragEventArgs e)
{
    if (e.Data.GetDataPresent(DataFormats.FileDrop))
    {
        string file = (string)e.Data.GetData(DataFormats.FileDrop);
        if (Path.GetExtension(file) != "dat")
        {
            s = "broken file";
        }
    }
}
1
You have to show us your "unshown" code. - LarsTech
I added it. Sorry. - snorepion
If you have UAC turned on and you're running the program as an Administrator, you won't be able to drag and drop something from Windows Explorer onto your form. - Connor

1 Answers

0
votes

You have to set the Effect property in the DragEnter event:

void textBox1_DragEnter(object sender, DragEventArgs e) {
  e.Effect = DragDropEffects.Copy;
  // your code...
}