今天因为要用到图片拖拉操作,所以简单的看了下,做了一个简单的demo,先来张效果图:
code is simple:
Code
public partial class 图片拖放 : Form
{
public 图片拖放()
{
InitializeComponent();
}
PictureBox pb = null;
private void 图片拖放_Load(object sender, EventArgs e)
{
panel1.AllowDrop = true;
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
this.pictureBox1.DoDragDrop(this.pictureBox1.Image, DragDropEffects.Copy);
}
private void panel1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
private void panel1_DragDrop(object sender, DragEventArgs e)
{
pb = new PictureBox();
pb.Image = (Image)e.Data.GetData(DataFormats.Bitmap);
pb.Size = new Size(26, 24);
pb.Location = new Point(e.X - 105 - Location.X, e.Y - 30 - Location.Y);
this.panel1.Controls.Add(pb);
}
}
public partial class 图片拖放 : Form
{
public 图片拖放()
{
InitializeComponent();
}
PictureBox pb = null;
private void 图片拖放_Load(object sender, EventArgs e)
{
panel1.AllowDrop = true;
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
this.pictureBox1.DoDragDrop(this.pictureBox1.Image, DragDropEffects.Copy);
}
private void panel1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
private void panel1_DragDrop(object sender, DragEventArgs e)
{
pb = new PictureBox();
pb.Image = (Image)e.Data.GetData(DataFormats.Bitmap);
pb.Size = new Size(26, 24);
pb.Location = new Point(e.X - 105 - Location.X, e.Y - 30 - Location.Y);
this.panel1.Controls.Add(pb);
}
}