I'm going to create a game. picturebox1 and picturebox4 have different images, picturebox2 and picturebox3 have no image. I want two different movement operations. i want to move the image from picturebox1 to picturebox2 and the Image from picturebox4 to picturebox3. But in the code I wrote, if I drag the first picturebox1, I can drop it to picturebox2 as I want, but when I select picturebox4, the second operation, I can't drop it to picturebox3 and it allows me to drop it to picturebox2. Or if I drag the first picturebox4, I can drop it to picturebox3 as I want, but when I select the second process, picturebox1, I can't drop it to picturebox2, and it allows me to drop it to picturebox3. How can I solve this problem in visual studio form application ?
enter code here
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 picturebox
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
pictureBox2.AllowDrop = true;
pictureBox3.AllowDrop = true;
label1.Visible = false;
label2.Visible = false;
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
((PictureBox)sender).DoDragDrop(((PictureBox)sender).Image, DragDropEffects.Copy);
}
private void pictureBox2_DragDrop(object sender, DragEventArgs e)
{
label1.Visible = false;
Image getPicture = (Bitmap)e.Data.GetData(DataFormats.Bitmap);
pictureBox2.Image = getPicture;
}
private void pictureBox2_DragEnter(object sender, DragEventArgs e)
{
label1.Visible = true;
pictureBox3.AllowDrop = false;
if (e.Data.GetDataPresent(DataFormats.Bitmap))
{
e.Effect = DragDropEffects.Copy;
}
}
private void pictureBox2_DragLeave(object sender, EventArgs e)
{
label1.Visible = false;
}
private void pictureBox4_MouseDown(object sender, MouseEventArgs e)
{
((PictureBox)sender).DoDragDrop(((PictureBox)sender).Image, DragDropEffects.Copy);
}
private void pictureBox3_DragDrop(object sender, DragEventArgs e)
{
label2.Visible = false;
label1.Visible = true;
Image getPicture = (Bitmap)e.Data.GetData(DataFormats.Bitmap);
pictureBox3.Image = getPicture;
}
private void pictureBox3_DragEnter(object sender, DragEventArgs e)
{
label2.Visible = true;
pictureBox2.AllowDrop = false;
if (e.Data.GetDataPresent(DataFormats.Bitmap))
{
e.Effect = DragDropEffects.Copy;
}
}
private void pictureBox3_DragLeave(object sender, EventArgs e)
{
label2.Visible = false;
}
}
}

