COMO ARRASTAR UM COMPONETE DENTRO DO FORM

CAIO.FR.SP 25/02/2010 13:19:57
#335340
galera como faço pra poder arrastar um componete dentro de um form, para que o usuario o deixe na posição desejada?
NICOLLAS2 25/02/2010 14:43:05
#335351
veja o exemplo do amigo abaixo...

[quote][http://www.vbmania.com.br/pages/index.php?varModulo=Detalhe&varID=6390/quote]
CAIO.FR.SP 25/02/2010 15:40:12
#335358
é quase isso. so que quero mover apenas um image. pq vou usar ele como um gadgat sabe isso vista e seven.
alguem mais pode me ajudar?
DEZ2 25/02/2010 17:52:24
#335373
Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
If TypeOf Source Is Image Then
With Source
.Left = X
.Top = Y
End With
End If
End Sub

Você tem que setar a propriedade DragDrop para auto
NICOLLAS2 25/02/2010 18:39:30
#335385
só altere o codigo do DEZ2 assim

Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
If TypeOf Source Is Image Then
With Source
.Left = X - (Source.Width / 2)
.Top = Y - (Source.Height / 2)
End With
End If
End Sub

dessa forma ele vai centralizar a posição do mouse...
CAIO.FR.SP 25/02/2010 18:59:36
#335391
deu quase certoquando eu clico e arrasto, a borda se move, mas depois quando solto o clique a imagem fika no mesmo lugar
MARCELO.TREZE 25/02/2010 21:40:07
#335406
Resposta escolhida
tente isto

[ô]Abra um formulário, adicione um CommandButton,
[ô]um Label e um PictureBox
[ô]Move tembém o Formulário sem barra de título
[ô]Declare
Dim MoveObjeto As Object
Dim MoveForm As Form
Dim MouseX As Long, MouseY As Long
[ô]-----------------------
Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If (Button = 1) Then
Set MoveObjeto = Command1
MouseX = X
MouseY = Y
End If
End Sub

Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If (Button = 1) Then
Command1.Left = Command1.Left + X - MouseX
Command1.Top = Command1.Top + Y - MouseY
End If
End Sub

Private Sub Form_Load()
Me.BorderStyle = 0
Set MoveForm = Me
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
MouseX = X
MouseY = Y
End If
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If (Button = 1) And (MoveForm.WindowState <> 2) Then
Screen.ActiveForm.Left = Screen.ActiveForm.Left + X - MouseX
Screen.ActiveForm.Top = Screen.ActiveForm.Top + Y - MouseY
End If
End Sub

Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Set MoveObjeto = Label1
MouseX = X
MouseY = Y
End If
End Sub

Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If (Button = 1) Then
Label1.Left = Label1.Left + X - MouseX
Label1.Top = Label1.Top + Y - MouseY
End If
End Sub

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If (Button = 1) Then
Set MoveObjeto = Picture1
MouseX = X
MouseY = Y
End If
End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If (Button = 1) Then
Picture1.Left = Picture1.Left + X - MouseX
Picture1.Top = Picture1.Top + Y - MouseY
End If
End Sub
TECLA 25/02/2010 22:10:21
#335408
Tente assim:

[txt-color=#007100][ô] Declare as variaveis no no General Declarations[/txt-color]
Dim posX As Integer, posY As Integer


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


Private Sub Form_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
If TypeOf Source Is Picture Then
posX = X
posY = Y
End If
End Sub
Tópico encerrado , respostas não são mais permitidas