private void panel1_MouseDown(object sender, MouseEventArgs e) { Panel mypic = (Panel)sender; mypic.DoDragDrop(mypic.BackgroundImage, DragDropEffects.Move); panel1.Location = loc; }
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace ContrloCircuit{ public partial class Form1 : Form { protected Point loc; private PictureBox selectpic; protected Panel panel1 = new Panel(); public Form1() { InitializeComponent(); Image img = Image.FromFile(@"E:dog.jpg"); this.picBox.AllowDrop = true; this.picBox.DragDrop += new System.Windows.Forms.DragEventHandler(this.picBox_DragDrop); this.picBox.DragEnter += new System.Windows.Forms.DragEventHandler(this.picBox_DragEnter); } private void pictureBox1_Click(object sender, EventArgs e) { picBox.Controls.Add(panel1); panel1.BackgroundImage = pictureBox1.Image; panel1.Height = pictureBox1.Height; panel1.Width = pictureBox1.Width; panel1.AllowDrop = true; // panel1.BackgroundImage = pictureBox1.Image; // panel1.AllowDrop = true; } private void picBox_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.Bitmap)) { e.Effect = DragDropEffects.Move; } else { e.Effect = DragDropEffects.None; } } private void picBox_DragDrop(object sender, DragEventArgs e) { // PictureBox picbox = (PictureBox)sender; // Graphics g = picbox.CreateGraphics(); // g.DrawImage((Image)e.Data.GetData(DataFormats.Bitmap), myloc); // label1.Text = myloc.ToString(); PictureBox destination = (PictureBox)sender; destination.Image = (Bitmap)e.Data.GetData(typeof(Bitmap)); } private void panel1_MouseDown(object sender, MouseEventArgs e) { Panel mypic = (Panel)sender; mypic.DoDragDrop(mypic.BackgroundImage, DragDropEffects.Move); panel1.Location = loc; } private void panel1_DragOver(object sender, DragEventArgs e) { // myloc.X = e.X; // myloc.Y = e.Y; panel1.Location = loc; } private void timer1_Tick(object sender, EventArgs e) { loc = Cursor.Position; label1.Text = loc.ToString(); } private void panel1_DragEnter(object sender, DragEventArgs e) { panel1.Location = loc; } }}