![](https://img2020.cnblogs.com/blog/508489/202104/508489-20210420191324256-1237242021.jpg)
基于Csharp的属性、动作,添加相关委托操作,实现图相框的拖拽。
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
pictureBox1.AllowDrop = true;
pictureBox2.AllowDrop = true;
pictureBox3.AllowDrop = true;
pictureBox1.MouseMove += SenderPB_MouseMove;
pictureBox3.MouseMove += SenderPB_MouseMove;
}
private void SenderPB_MouseMove(object sender, MouseEventArgs e)
{
PictureBox thisPB = (PictureBox)sender;
if ((e.Button & MouseButtons.Left) == MouseButtons.Left && (thisPB.Image != null))
{
Bitmap b = new Bitmap(thisPB.Image);
DragDropEffects eff = ((PictureBox)sender).DoDragDrop(b, DragDropEffects.Copy);
}
}
private void pictureBox2_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
private void pictureBox2_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Bitmap)))
{
this.pictureBox2.Image = (Bitmap)e.Data.GetData(typeof(Bitmap));
}
}
}