+92 332 4229 857 99ProjectIdeas@Gmail.com

Drag And Drop Image On Form (C#.net)

The following code shows you dragging and dropping an image on form and setting that image the background of the form... using drag drop event of form. And also shows the path of dragged image.

private void Form1_DragDrop(object sender, DragEventArgs e)
     if (e.Data.GetDataPresent(DataFormats.FileDrop))
         string[] list = (string[])e.Data.GetData(DataFormats.FileDrop,false);
         Image img = Image.FromFile(list[0]);
         this.BackgroundImage = img;
         this.BackgroundImageLayout = ImageLayout.Center;
            foreach (string file in list)
                    this.label1.Text += file + "\n";