日期:2014-05-17 浏览次数:21069 次
public Form1()
{
InitializeComponent();
picLeft.AllowDrop = true;
picRight.AllowDrop = true;
}
//左边PictureBox鼠标按下时激发操作
private void picLeft_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
PictureBox pic = (PictureBox)(sender);
if (pic.BackgroundImage != null)
{
pic.DoDragDrop(pic.BackgroundImage , DragDropEffects.Copy);//拖放操作
}
}
}
private void picRight_DragEnter(object sender, DragEventArgs e)
{
// 检查该图片是否适用于目标控件。如果不适用,则拒绝放置图片。
if (e.Data.GetDataPresent(DataFormats.Bitmap))
{
e.Effect = DragDropEffects.Copy;//执行复制操作
}
else
{
e.Effect = DragDropEffects.None;
}
}