Arrastrar y soltar (drap y drop) en visual basic.net

Hola a todos, hoy desarrollaremos una práctica sobre arrastrar y soltar (drap y drop), esto se debe a que no solo es importante conocer cada vez más sobre programación (Claro que es muy importante, y primordial), sino también por comprender un poco que nuestros productos van enfocados al uso de usuarios finales(clientes u otros) y estos usuarios se clasifican en dos, los usuarios del teclado que les encanta escribir mucho, y los usuarios del mouse, que prefieren solo hacer operaciones  básicas como nuestro caso, de arrastrar y soltar objetos, además digamos algo ¿a quién no le gusta trabajar con el mouse?.

Una vista previa de lo que sera nuestra Practica:



Información técnica sobre la aplicación:




Esta desarrollada con visual basic.NET 2004 y framework 4.0, y pues se enfoca al uso de drap y drop, para obtener más información sobre: drap y drop, consultar un poco en internet, encontraran mucha ayuda, ya que para nuestro fin, solo realizamos practicas que ustedes puedan descargar y aplicar, y también decir que hay un formulario principal que acopla el arrastrar y soltar de texto, imágenes y archivos, y un formulario para cada uno de estos procedimientos, para que sea estudiado y comprendido mejor.

Algo de código fuente, arrastrar imagenes:

  1 Public Class ArrasrarImgs
  2     Private img As Image
  3     Private imglocalizacion As Point
  4  
  5     Private Sub ArrasrarImgs_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragDrop
  6         If e.Data.GetDataPresent(DataFormats.FileDrop) Then
  7             ' Assign the file names to a string array, in 
  8             ' case the user has selected multiple files.
  9             Dim files As String() = CType(e.Data.GetData(DataFormats.FileDrop), String())
 10             Try 
 11                 ' Assign the first image to the 'picture' variable.
 12                 Me.img = Image.FromFile(files(0))
 13                 ' Set the picture location equal to the drop point.
 14  
 15                 Me.Foto2.Image = Me.img
 16                 ' Me.imglocalizacion = Me.PointToClient(New Point(e.X, e.Y))
 17             Catch ex As Exception
 18                 MessageBox.Show(ex.Message) 
 19                 Return 
 20             End Try
 21         End If
 22  
 23         ' Handle Bitmap data. 
 24         If e.Data.GetDataPresent(DataFormats.Bitmap) Then
 25             Try 
 26                 ' Create an Image and assign it to the picture variable.
 27                 Me.img = CType(e.Data.GetData(DataFormats.Bitmap), Image)
 28                 ' Set the picture location equal to the drop point.
 29                 Me.imglocalizacion = Me.PointToClient(New Point(e.X, e.Y))
 30             Catch ex As Exception
 31                 MessageBox.Show(ex.Message) 
 32                 Return 
 33             End Try
 34         End If
 35  
 36         ' Force the form to be redrawn with the image.
 37         Me.Invalidate() 
 38     End Sub
 39  
 40     Private Sub ArrasrarImgs_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragEnter
 41         If e.Data.GetDataPresent(DataFormats.Bitmap) _
 42       Or e.Data.GetDataPresent(DataFormats.FileDrop) Then
 43             e.Effect = DragDropEffects.Copy 
 44         Else 
 45             e.Effect = DragDropEffects.None 
 46         End If
 47     End Sub
 48  
 49  
 50     Private Sub ArrasrarImgs_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 51         Me.AllowDrop = True
 52     End Sub
 53  
 54  
 55     Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
 56         MyBase.OnPaint(e) 
 57  
 58          
 59         If (Me.img IsNot Nothing) And _
 60           Not (Me.imglocalizacion.Equals(Point.Empty)) Then
 61             e.Graphics.DrawImage(Me.img, Me.imglocalizacion)
 62         End If
 63     End Sub
 64  
 65  
 66 End Class

código fuente, arrastrar texto:

  1 Public Class FormrArrastrarTexto
  2     Private MouseIsDown As Boolean = False
  3     'establecer la propiedad AllowDrop de la caja2 como true
  4  
  5  
  6     Private Sub CajaConfirmacion_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles CajaConfirmacion.DragDrop
  7         CajaConfirmacion.Text = e.Data.GetData(DataFormats.Text) 
  8     End Sub
  9  
 10     Private Sub CajaConfirmacion_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles CajaConfirmacion.DragEnter
 11         ' Check the format of the data being dropped.
 12  
 13         If (e.Data.GetDataPresent(DataFormats.Text)) Then
 14             ' Display the copy cursor. 
 15             e.Effect = DragDropEffects.Copy 
 16         Else 
 17             ' Display the no-drop cursor.
 18             e.Effect = DragDropEffects.Copy 
 19         End If
 20     End Sub
 21  
 22  
 23     Private Sub CajaCorreo_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles CajaCorreo.MouseDown
 24  
 25         'primero que todo activo este flag o alerta que me avisa que se hizo clcik en la caja
 26         MouseIsDown = True 
 27     End Sub
 28  
 29     Private Sub CajaCorreo_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles CajaCorreo.MouseMove
 30         'si se hizo click en la caja y el usuario 
 31         'mueve el mouse mientras el puntero está sobre la caja
 32         If MouseIsDown Then
 33             'inicio la operacion de arrastar y colocar
 34             CajaCorreo.DoDragDrop(CajaCorreo.Text, DragDropEffects.Copy) 
 35         End If
 36         MouseIsDown = False 
 37  
 38     End Sub
 39  
 40 End Class
 41 


código fuente, arrastrar Archivos:




  1 Public Class arrastrarARchivos
  2  
  3  
  4     Private Sub arrastrarARchivos_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  5         Me.AllowDrop = True
  6         Me.Caja1.AllowDrop = True
  7     End Sub
  8  
  9     Private Sub Caja1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Caja1.DragDrop
 10        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
 11             Dim MyFiles() As String
 12             Dim i As Integer
 13  
 14             ' Assign the files to an array.
 15             MyFiles = e.Data.GetData(DataFormats.FileDrop) 
 16             ' Loop through the array and add the files to the list.
 17  
 18  
 19  
 20             If MyFiles.Length > 0 Then
 21  
 22                 Me.Caja1.Multiline = True
 23                 Me.Caja1.ScrollBars = ScrollBars.Both
 24                 For i = 0 To MyFiles.Length - 1 
 25                     ' ListBox1.Items.Add(MyFiles(i))
 26                     Caja1.Text = Caja1.Text & MyFiles(i) & vbNewLine 
 27                 Next 
 28             Else 
 29                 Caja1.Text = MyFiles(0) 
 30             End If
 31              
 32         End If
 33     End Sub
 34  
 35     Private Sub Caja1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Caja1.DragEnter
 36         If e.Data.GetDataPresent(DataFormats.FileDrop) Then
 37             e.Effect = DragDropEffects.All 
 38         End If
 39     End Sub
 40  
 41     Private Sub Caja1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Caja1.TextChanged
 42  
 43     End Sub
 44 End Class
 45 











No siendo mas espero les halla agradado esta practica y pues no se les olvide sigan pendiente del blog.

Algoritmo:Convertir número décimal a hexadecimal en Java

Hola…   En este post quiero os  regalar un algoritmo (de mi autoría) que he realizado en pseudocódigo a lápiz y papel, pero se los regalaré en un lenguaje en el cuál aún no estoy acostumbrado a programar, Java.
El Algoritmo es fácil y sencillo, espero te sirva de ayuda:
método (ó función):    firstHex(int dec): Recibe como parámetro un numero décimal menor que 16. Sirve para convertir los numeros del 10 al 15 a su equivalente en Hexadecimal (A,B,C,D,E ó F).  Si es un numero menor que 10 devuelve el mismo número.
1 public String firstHex(int dec) {
  2         String numeroHex=""; 
  3         if(dec<16) {
  4             switch(dec) { 
  5                     case 10:
  6                     numeroHex="A"; 
  7                     break; 
  8                     case 11:
  9                     numeroHex="B"; 
 10                     break; 
 11                     case 12:
 12                     numeroHex="C"; 
 13                     break; 
 14                     case 13:
 15                     numeroHex="D"; 
 16                     break; 
 17                     case 14:
 18                     numeroHex="E"; 
 19                     break; 
 20                     case 15:
 21                     numeroHex="F"; 
 22                     break; 
 23                     default: 
 24                     numeroHex=Integer.toString(dec); 
 25                     break; 
 26                 } 
 27             return numeroHex; 
 28         } else { 
 29         return "false";
 30         } 
 31     }
método (ó función):   toHex(int dec): Recibe como parámetro un numero décimal cualquiera (menor, igual o mayor que 16).  Su función es de convertir totalmente el número en Hexadecimal.  Hace uso defirstHex(int dec).




  1 public String toHex(int dec) {
  2         int cociente=16, residuo=0;
  3         String numeroHex="", numeroHex1="";
  4         if(dec<16)
  5          {
  6              numeroHex=firstHex(dec);
  7          } else 
  8            {
  9              do 
 10               {
 11                cociente=dec/16;
 12                residuo=dec%16;
 13                dec=cociente;
 14                numeroHex1=firstHex(residuo);
 15                numeroHex=numeroHex1+numeroHex;
 16                dec=cociente;         
 17               } while (dec&gt;=16);
 18         numeroHex1=firstHex(dec);
 19         numeroHex=numeroHex1+numeroHex;
 20         }
 21         return numeroHex;
 22     }

Por ultimo sólo es llamar el método (o función) toHex(int dec). Ejemplo:  Queremos convertir el número 349.



  1 String numeroHexadecimal;
  2 numeroHexadecimal=toHex(349);