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