Ver Mensaje Individual
  #2 (permalink)  
Antiguo 11/01/2012, 18:40
Avatar de drako_darpan
drako_darpan
 
Fecha de Ingreso: octubre-2008
Ubicación: Sinaloa
Mensajes: 617
Antigüedad: 15 años, 7 meses
Puntos: 58
Respuesta: Arrastrar y soltar (drag&drop)

Hola que tal, bueno gracias a tu duda me quedo mas clara una pregunta similar a tu duda , un pequeño Deja VU

Para el Drag&Drop en C#, seria asi:

Código C#:
Ver original
  1. private Image picture;
  2.         private Point pictureLocation;
  3.  
  4.         public Form1()
  5.         {
  6.             InitializeComponent();
  7.         }
  8.  
  9.         private void Form1_Load(object sender, EventArgs e)
  10.         {
  11.             this.AllowDrop = true;
  12.             this.DragDrop += new DragEventHandler(this.Form1_DragDrop);
  13.             this.DragEnter += new DragEventHandler(this.Form1_DragEnter);
  14.         }
  15.  
  16.         protected override void OnPaint(PaintEventArgs e)
  17.         {
  18.            // If there is an image and it has a location,
  19.            // paint it when the Form is repainted.
  20.            base.OnPaint(e);
  21.            if(this.picture != null && this.pictureLocation != Point.Empty)
  22.            {
  23.               e.Graphics.DrawImage(this.picture, this.pictureLocation);
  24.            }
  25.         }
  26.  
  27.         private void Form1_DragDrop(object sender, DragEventArgs e)
  28.         {
  29.            // Handle FileDrop data.
  30.            if(e.Data.GetDataPresent(DataFormats.FileDrop) )
  31.            {
  32.               // Assign the file names to a string array, in
  33.               // case the user has selected multiple files.
  34.               string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
  35.               try
  36.               {
  37.                  // Assign the first image to the picture variable.
  38.                  this.picture = Image.FromFile(files[0]);
  39.                  // Set the picture location equal to the drop point.
  40.                  this.pictureLocation = this.PointToClient(new Point(e.X, e.Y) );
  41.               }
  42.               catch(Exception ex)
  43.               {
  44.                  MessageBox.Show(ex.Message);
  45.                  return;
  46.               }
  47.            }
  48.  
  49.            // Handle Bitmap data.
  50.            if(e.Data.GetDataPresent(DataFormats.Bitmap) )
  51.            {
  52.               try
  53.               {
  54.                  // Create an Image and assign it to the picture variable.
  55.                  this.picture = (Image)e.Data.GetData(DataFormats.Bitmap);
  56.                  // Set the picture location equal to the drop point.
  57.                  this.pictureLocation = this.PointToClient(new Point(e.X, e.Y) );
  58.               }
  59.               catch(Exception ex)
  60.               {
  61.                  MessageBox.Show(ex.Message);
  62.                  return;
  63.               }
  64.            }
  65.            // Force the form to be redrawn with the image.
  66.            this.Invalidate();
  67.         }
  68.  
  69.         private void Form1_DragEnter(object sender, DragEventArgs e)
  70.         {
  71.             // If the data is a file or a bitmap, display the copy cursor.
  72.             if (e.Data.GetDataPresent(DataFormats.Bitmap) ||
  73.                e.Data.GetDataPresent(DataFormats.FileDrop))
  74.             {
  75.                 e.Effect = DragDropEffects.Copy;
  76.             }
  77.             else
  78.             {
  79.                 e.Effect = DragDropEffects.None;
  80.             }
  81.         }

El ejemplo lo revise en MSD de esta ruta:
http://msdn.microsoft.com/es-es/libr...=vs.90%29.aspx

Espero te sirva, si funciona por que ya lo probe, pero ahora quiero poder mover la imagen que anexe , pero eso me toca buscarle a mi, suerte