Visual Basic - Arrastrar controles sobre un formulario

Life is soft - evento anual de software empresarial
 
Vista:

Arrastrar controles sobre un formulario

Publicado por Ibrahim Tejera (3 intervenciones) el 23/09/2003 00:28:47
Necesito saber como arrastrar controles sobre un formulario hacia una posicion determinada, si alguien puede ayudarme, se lo agradesco, gracias.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Arrastrar controles sobre un formulario

Publicado por Juan (284 intervenciones) el 23/09/2003 15:20:01
Te pongo un ejemplo:

Option Explicit
Dim iniX As Long, iniY As Long, ctrlSource As Control

Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
capturaArrastre Text1, x, y
End Sub

Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
sueltaArrastre x, y
End Sub

Private Sub capturaArrastre(ByRef ctrl As Control, ByVal x As Long, ByVal y As Long)
iniX = x
iniY = y
Set ctrlSource = Text1
End Sub
Private Sub sueltaArrastre(ByVal x As Long, ByVal y As Long)
If Not ctrlSource Is Nothing Then
ctrlSource.Move ctrlSource.Left + x - iniX, ctrlSource.Top + y - iniY
Set ctrlSource = Nothing
End If
End Sub

En este ejemplo sólo se mueve un textBox llamado Text1, pero se usa
igual con cualquier control siempre que en sus eventos llames a las funciones capturaArrastre y sueltaArrastre de forma adecuada.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Arrastrar controles sobre un formulario

Publicado por SyddlE (11 intervenciones) el 17/02/2004 15:10:13
Aqui te muestro otra forma de arrastrar objetos:

Option Explicit
Public globalX As Integer
Public globalY As Integer

Private Sub Form_DragDrop(Source As Control, X As _
Single, Y As Single)
Picture1.Move X - globalX, Y - globalY
End Sub

Private Sub picture1_MouseDown(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
Picture1.Drag vbBeginDrag
globalX = X
globalY = Y
End Sub

Para ver el ejemplo solo agrega un PICTURE a tu formulario, copia y pega este codigo y ya, tambien puedes usarlo para cualquier control.

Espero te sirva.....
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar