1
通過此代碼,我可以將圖像拖放到標籤上,但現在我想將該圖像從標籤拖動到另一個標籤。我怎樣才能做到這一點?拖放圖像
namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
Image img = Image.FromFile(@"D:\test\test.png");
this.btnImage.Image = img;
Image img1 = Image.FromFile(@"C:\Documents and Settings\SAURABH\Desktop\Green.ico");
this.btnImage1.Image = img1;
}
private void button1_MouseDown(object sender, MouseEventArgs e)
{
Button btnPic = (Button)sender;
btnPic.DoDragDrop(btnPic.Image, DragDropEffects.Copy);
}
private void button2_MouseDown(object sender, MouseEventArgs e)
{
Button btnPic = (Button)sender;
btnPic.DoDragDrop(btnPic.Image, DragDropEffects.Copy);
}
private void button3_MouseDown(object sender, MouseEventArgs e)
{
Button btnPic = (Button)sender;
btnPic.DoDragDrop(btnPic.Image, DragDropEffects.Copy);
}
private void label1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Bitmap))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void label10_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Bitmap))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void label10_DragDrop(object sender, DragEventArgs e)
{
Label picbox = (Label)sender;
//PictureBox picbox = (PictureBox)sender;
Graphics g = picbox.CreateGraphics();
g.DrawImage((Image)e.Data.GetData(DataFormats.Bitmap), new Point(0, 0));
}
private void label1_DragDrop(object sender, DragEventArgs e)
{
Label picbox = (Label)sender;
//PictureBox picbox = (PictureBox)sender;
Graphics g = picbox.CreateGraphics();
g.DrawImage((Image)e.Data.GetData(DataFormats.Bitmap), new Point(0, 0));
}
}
}