18-02-2016, 17:50
İki PictureBox arasında sürükle bırak yoluyla resim aktarmaya ilişkin, internette denk geldiğim güzel bir örnek.
//In the Form Load
//Set AllowDrop of the Target PictureBox to true as this property cannot be set in the Designer (Form Load)
//Source PictureBox
//Target PictureBox
//Drag Drop Effects
//Set the image to be the dragged image.
//In the Form Load
//Set AllowDrop of the Target PictureBox to true as this property cannot be set in the Designer (Form Load)
Kod:
this.pictureBox2.AllowDrop = true;
//Source PictureBox
Kod:
private void pictureBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
pictureBox1.DoDragDrop( pictureBox1.Image, DragDropEffects.All );
}
//Target PictureBox
//Drag Drop Effects
Kod:
private void pictureBox2_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
{
if ( e.Data.GetDataPresent( DataFormats.Bitmap ) )
{
e.Effect = DragDropEffects.Copy;
}
else
e.Effect = DragDropEffects.None;
}
//Set the image to be the dragged image.
Kod:
private void pictureBox2_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
if ( (e.Data.GetDataPresent(DataFormats.Bitmap)))
{
this.pictureBox1.Image = (Bitmap)(e.Data.GetData(DataFormats.Bitmap));
}
}