I am building a simple drag and drop game using windows forms. Its like a jigsaw puzzle. I want to drag pictures from one form to another to complete the puzzle. Is there a way to do this with a PictureBox. It seems to be the only property without the AllowDrop function. Source code below.
I want to drag images from the form on the left to the form on the right.
I was following this tutorial but I cannot get my head around it. C# Drag and Drop from one Picture box into Another
Form Right
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 DragDropGame
{
public partial class ChildFormTwo : Form
{
public ChildFormTwo()
{
InitializeComponent();
pictureBox3.DragEnter += pictureBox3_DragEnter;
pictureBox3.DragDrop += pictureBox3_DragDrop;
}
private void pictureBox3_DragDrop(object sender, DragEventArgs e)
{
var bmp = (Bitmap)e.Data.GetData(DataFormats.Bitmap);
pictureBox2.Image = bmp;
}
private void pictureBox3_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Bitmap))
e.Effect = DragDropEffects.Move;
}
}
}
Form Left
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 DragDropGame
{
public partial class ChildFormTwo : Form
{
public ChildFormTwo()
{
InitializeComponent();
pictureBox3.DragEnter += pictureBox3_DragEnter;
pictureBox3.DragDrop += pictureBox3_DragDrop;
}
private void pictureBox3_DragDrop(object sender, DragEventArgs e)
{
var bmp = (Bitmap)e.Data.GetData(DataFormats.Bitmap);
pictureBox2.Image = bmp;
}
private void pictureBox3_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Bitmap))
e.Effect = DragDropEffects.Move;
}
}
}