using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DragAndDropImages
{
    public partial class frm91DragAndDropImages : Form
    {
        public frm91DragAndDropImages()
        {
            InitializeComponent();
        }

        // Set the drop target PictureBox's AllowDrop property at run time.
        // It's not available in the Properties window or IntelliSense.
        private void frm91DragAndDropImages_Load(object sender, EventArgs e)
        {
            dropTargetPictureBox.AllowDrop = true;
        }

        // Start the drag.
        private void dragSourcePictureBox_MouseDown(object sender, MouseEventArgs e)
        {
            // Start the drag if it's the right mouse button.
            if (e.Button == MouseButtons.Right)
            {
                dragSourcePictureBox.DoDragDrop(
                    dragSourcePictureBox.Image, DragDropEffects.Copy);
            }
        }

        // Allow a copy of an image.
        private void dropTargetPictureBox_DragEnter(object sender, DragEventArgs e)
        {
            // See if this is a copy and the data includes an image.
            if (e.Data.GetDataPresent(DataFormats.Bitmap, true) &&
                (e.AllowedEffect & DragDropEffects.Copy) != 0)
            {
                // Allow this.
                e.Effect = DragDropEffects.Copy;
            }
            else
            {
                // Don't allow any other drop.
                e.Effect = DragDropEffects.None;
            }
        }

        // Accept the drop.
        private void dropTargetPictureBox_DragDrop(object sender, DragEventArgs e)
        {
            dropTargetPictureBox.Image =
                (Bitmap)e.Data.GetData(DataFormats.Bitmap, true);
        }


        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.label2 = new System.Windows.Forms.Label();
            this.dropTargetPictureBox = new System.Windows.Forms.PictureBox();
            this.label1 = new System.Windows.Forms.Label();
            this.dragSourcePictureBox = new System.Windows.Forms.PictureBox();
            ((System.ComponentModel.ISupportInitialize)(this.dropTargetPictureBox)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.dragSourcePictureBox)).BeginInit();
            this.SuspendLayout();
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(12, 130);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(67, 13);
            this.label2.TabIndex = 7;
            this.label2.Text = "Drop Target:";
            // 
            // picDropTarget
            // 
            this.dropTargetPictureBox.BackColor = System.Drawing.Color.White;
            this.dropTargetPictureBox.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.dropTargetPictureBox.Location = new System.Drawing.Point(12, 146);
            this.dropTargetPictureBox.Name = "picDropTarget";
            this.dropTargetPictureBox.Size = new System.Drawing.Size(100, 100);
            this.dropTargetPictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
            this.dropTargetPictureBox.TabIndex = 6;
            this.dropTargetPictureBox.TabStop = false;
            this.dropTargetPictureBox.DragDrop += new System.Windows.Forms.DragEventHandler(this.dropTargetPictureBox_DragDrop);
            this.dropTargetPictureBox.DragEnter += new System.Windows.Forms.DragEventHandler(this.dropTargetPictureBox_DragEnter);
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(12, 9);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(70, 13);
            this.label1.TabIndex = 5;
            this.label1.Text = "Drag Source:";
            // 
            // picDragSource
            // 
            this.dragSourcePictureBox.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.dragSourcePictureBox.Image = global::DragAndDropImages.Properties.Resources.banner;
            this.dragSourcePictureBox.Location = new System.Drawing.Point(12, 25);
            this.dragSourcePictureBox.Name = "picDragSource";
            this.dragSourcePictureBox.Size = new System.Drawing.Size(274, 88);
            this.dragSourcePictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
            this.dragSourcePictureBox.TabIndex = 4;
            this.dragSourcePictureBox.TabStop = false;
            this.dragSourcePictureBox.MouseDown += new System.Windows.Forms.MouseEventHandler(this.dragSourcePictureBox_MouseDown);
            // 
            // frm91DragAndDropImages
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(298, 256);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.dropTargetPictureBox);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.dragSourcePictureBox);
            this.Name = "frm91DragAndDropImages";
            this.Text = "DragAndDropImages";
            this.Load += new System.EventHandler(this.frm91DragAndDropImages_Load);
            ((System.ComponentModel.ISupportInitialize)(this.dropTargetPictureBox)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.dragSourcePictureBox)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.PictureBox dropTargetPictureBox;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.PictureBox dragSourcePictureBox;
    }
}