Foro de elhacker.net

Programación => Programación Visual Basic => Mensaje iniciado por: aaronduran2 en 5 Agosto 2008, 18:09 pm



Título: Drag & Drop de un texto
Publicado por: aaronduran2 en 5 Agosto 2008, 18:09 pm
Hola. Quisiera saber como hacer drag & drop de un texto, de forma que tenemos un TextBox y queremos pasar su contenido a otro. Lo he intentado con las funciones que incluyen los TextBox, pero no soy capaz.

Gracias de antemano.


Título: Re: Drag & Drop de un texto
Publicado por: seba123neo en 5 Agosto 2008, 18:27 pm
Hola,pues se me ocurre asi,puede haber otras formas...

Código
  1. Option Explicit
  2.  
  3. Private Sub Form_Load()
  4. Text1.OLEDragMode = 1
  5. Text2.OLEDropMode = 1
  6. End Sub
  7.  
  8. Private Sub Text1_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
  9. Text1.OLEDrag
  10. End Sub
  11.  
  12. Private Sub Text2_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
  13. Text2.Text = Data.GetData(1)
  14. End Sub

saludos.


Título: Re: Drag & Drop de un texto
Publicado por: aaronduran2 en 5 Agosto 2008, 21:41 pm
Hola, seba123neo. Gracias por la ayuda. Pero no me funciona. Cuando arrastro lo que pone en el TextBox y lo pongo sobre otro, se ve el cursor de arrastrar, pero lo suelo y no hace nada. ¿Tendrá algo que ver que estén bloqueados para impedir su modificación?

Saludos.


Título: Re: Drag & Drop de un texto
Publicado por: Angeldj27 en 5 Agosto 2008, 23:00 pm
Chekeate este si funciona
Código:
Private Sub Text1_DragDrop(Source As Control, X As Single, Y As Single)
Text1.Text = Text2.Text

End Sub

Tienes que poner el DragMode del text2 en 1

Talves te funcione


Título: Re: Drag & Drop de un texto
Publicado por: aaronduran2 en 5 Agosto 2008, 23:04 pm
Gracias, pero lo que pasa es que tengo 6 TextBox y quiero que se pueda elegir el que se va a pasar.

Saludos


Título: Re: Drag & Drop de un texto
Publicado por: seba123neo en 6 Agosto 2008, 03:37 am
proba el codigo que te puse yo en un proyecto nuevo y vas a ver que funciona...despues fijate en el tuyo como armarlo...tenes que seleccionar el texto que queres arrastrar para que funcione...


Título: Re: Drag & Drop de un texto
Publicado por: aaronduran2 en 6 Agosto 2008, 10:37 am
Lo probé en un proyecto nuevo y si funciona, pero en el mío no.
A ver, este es el código que tengo yo:
Código
  1. Private Sub Form_Load()
  2. txtResultado1.OLEDragMode = 1
  3. txtResultado2.OLEDragMode = 1
  4. txtResultado3.OLEDragMode = 1
  5. txtResultado4.OLEDragMode = 1
  6. txtResultado5.OLEDragMode = 1
  7. txtResultado6.OLEDragMode = 1
  8. txtFuerza.OLEDropMode = 1
  9. txtDestreza.OLEDropMode = 1
  10. txtConstitucion.OLEDropMode = 1
  11. txtInteligencia.OLEDropMode = 1
  12. txtSabiduria.OLEDropMode = 1
  13. txtCarisma.OLEDropMode = 1
  14. End Sub
  15.  
  16. Private Sub txtCarisma_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
  17. txtCarisma.Text = Data.GetData(1)
  18. End Sub
  19.  
  20. Private Sub txtConstitucion_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
  21. txtConstitucion.Text = Data.GetData(1)
  22. End Sub
  23.  
  24.  
  25. Private Sub txtDestreza_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
  26. txtDestreza.Text = Data.GetData(1)
  27. End Sub
  28.  
  29. Private Sub txtFuerza_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
  30. txtFuerza.Text = Data.GetData(1)
  31. End Sub
  32.  
  33. Private Sub txtInteligencia_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
  34. txtInteligencia.Text = Data.GetData(1)
  35. End Sub
  36.  
  37. Private Sub txtSabiduria_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
  38. txtSabiduria.Text = Data.GetData(1)
  39. End Sub
  40.  
  41. Private Sub txtResultado1_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
  42. txtResultado1.OLEDrag
  43. End Sub
  44.  
  45. Private Sub txtResultado2_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
  46. txtResultado2.OLEDrag
  47. End Sub
  48.  
  49. Private Sub txtResultado3_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
  50. txtResultado3.OLEDrag
  51. End Sub
  52.  
  53. Private Sub txtResultado4_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
  54. txtResultado4.OLEDrag
  55. End Sub
  56.  
  57. Private Sub txtResultado5_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
  58. txtResultado5.OLEDrag
  59. End Sub
  60.  
  61. Private Sub txtResultado6_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
  62. txtResultado6.OLEDrag
  63. End Sub
  64.  
Y no me funciona... Si alguien sabe por qué.

Saludos.


Título: Re: Drag & Drop de un texto
Publicado por: seba123neo en 6 Agosto 2008, 18:56 pm
EDITADO: esta todo bien ...me fije mal... y una pregunta de que textbox a cual queres pasar por ejemplo...?


Título: Re: Drag & Drop de un texto
Publicado por: aaronduran2 en 6 Agosto 2008, 19:04 pm
Quiero pasar de los txtResultado a los otros. Estoy haciendo una especie de creador de personajes para D&D.

Estuve probando a utilizar Drag en vez de OLEDrag, pero me dice que el espacio de pila es insfuficiente.

Saludos.


Título: Re: Drag & Drop de un texto
Publicado por: seba123neo en 6 Agosto 2008, 19:15 pm
pues probe asi como el tuyo pero con 2 textbox y funciona,vos tenes que seleccionar el texto primero y despues ahi podes arrastrarlo..para ahorrarte seleccionarlo podes que cuando tome el foco el textbox se seleccione todo el texto...no tendran alguna propiedad activada qeu le cambiaste y por eso no anda,antes dijiste que estaban bloqueados,pero lo unico que les afecta es el Enabled = False pero con el Locked = True sige funcionando...

saludos.


Título: Re: Drag & Drop de un texto
Publicado por: aaronduran2 en 6 Agosto 2008, 19:17 pm
OK, gracias. No me había dado cuenta. Menuda tontería. Gracias de nuevo.

Saludos.