arrastre de botones en tiempo de ejecución.

carlos
20 de Abril del 2004
Hola amigos,

Mi aplicación dispone de una serie de botones, q me gustaria q de alguna forma, el usuario final pudiese situarlos en la parte q quisiera de la pantalla, en tiempo de ejecucion.
Para ello sé que el boton en ese momento debe esta 'inhabilitado', pero ¿con que opcion dejo que el usuario modifique la posicion de los botones?

Gracias.

rafa
20 de Abril del 2004
'Variables a nivel del módulo
Dim DY As Single
Dim DX As Single

Private Sub CancelarDrag(Source As Control)
Source.Visible = True
Source.Drag vbCancel
End Sub

Private Sub FinalizarDrag(Source As Control, Button As Integer)
If Button = vbLeftButton Then
Source.Visible = True
Source.ZOrder
Source.Drag vbEndDrag
End If
End Sub

Private Sub IniciarDrag(Source As Control, Button As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
DX = X
DY = Y
'Permitir la operación de Drag & Drop
Source.Drag vbBeginDrag
'Cambiar a no visible, ya que si no, el form no detectaría que se ha soltado, si el puntero del ratón no sale del control.
Source.Visible = False
'Comienza el espectáculo
Source.Drag
End If
End Sub

Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
'Si se quieren excluir algunos controles,
'hacer aquí la comparación.
Source.Visible = True
Source.Move X - DX -60, Y - DY -60
Source.Drag vbEndDrag
Source.ZOrder
End Sub

'En cada control poner este código:
(cambiar %Control% por el nombre apropiado)
'
Private Sub %Control%_DragDrop(Source As Control, X As Single, Y As Single)
CancelarDrag Source
End Sub
'
Private Sub %Control%_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
IniciarDrag %Control%, Button, X, Y
End Sub
'
Private Sub %Control%_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
FinalizarDrag %Control%, Button
End Sub