C# - How To Drag And Drop Image From Desktop To PictureBox In C#

How To Drag And Drop Image From Desktop To PictureBox In C#

____________________________________________________________

In This C# Code We Will See How To  You Can Drag Image From Your DesKtop And Drop It In The PictureBox In CSharp Programming Language .

Project Source Code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
namespace WindowsFormsApplication1
{
    public partial class Project : Form
    {
        public Project()
        {
            InitializeComponent();
            pictureBox1.AllowDrop = true;
        }
        private void pictureBox1_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.Copy;
        }
 
        private void pictureBox1_DragDrop(object sender, DragEventArgs e)
        {
            foreach(string pic in ((string[])e.Data.GetData(DataFormats.FileDrop)))
            {
                Image img = Image.FromFile(pic);
                pictureBox1.Image = img;
            }
        }
    }
}


Drag And Drop Image From Desktop To PictureBox In C#
Image From Desktop To PictureBox In C#




Share this

Related Posts

Previous
Next Post »