Test Foro de elhacker.net SMF 2.1

Programación => .NET (C#, VB.NET, ASP) => Programación General => 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 (vb) [Seleccionar]
Option Explicit

Private Sub Form_Load()
Text1.OLEDragMode = 1
Text2.OLEDropMode = 1
End Sub

Private Sub Text1_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
Text1.OLEDrag
End Sub

Private Sub Text2_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
Text2.Text = Data.GetData(1)
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

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 (vb) [Seleccionar]

Private Sub Form_Load()
txtResultado1.OLEDragMode = 1
txtResultado2.OLEDragMode = 1
txtResultado3.OLEDragMode = 1
txtResultado4.OLEDragMode = 1
txtResultado5.OLEDragMode = 1
txtResultado6.OLEDragMode = 1
txtFuerza.OLEDropMode = 1
txtDestreza.OLEDropMode = 1
txtConstitucion.OLEDropMode = 1
txtInteligencia.OLEDropMode = 1
txtSabiduria.OLEDropMode = 1
txtCarisma.OLEDropMode = 1
End Sub

Private Sub txtCarisma_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
txtCarisma.Text = Data.GetData(1)
End Sub

Private Sub txtConstitucion_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
txtConstitucion.Text = Data.GetData(1)
End Sub


Private Sub txtDestreza_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
txtDestreza.Text = Data.GetData(1)
End Sub

Private Sub txtFuerza_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
txtFuerza.Text = Data.GetData(1)
End Sub

Private Sub txtInteligencia_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
txtInteligencia.Text = Data.GetData(1)
End Sub

Private Sub txtSabiduria_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
txtSabiduria.Text = Data.GetData(1)
End Sub

Private Sub txtResultado1_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
txtResultado1.OLEDrag
End Sub

Private Sub txtResultado2_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
txtResultado2.OLEDrag
End Sub

Private Sub txtResultado3_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
txtResultado3.OLEDrag
End Sub

Private Sub txtResultado4_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
txtResultado4.OLEDrag
End Sub

Private Sub txtResultado5_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
txtResultado5.OLEDrag
End Sub

Private Sub txtResultado6_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
txtResultado6.OLEDrag
End Sub

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.