COMO ARRASTAR UM COMPONETE DENTRO DO FORM
galera como faço pra poder arrastar um componete dentro de um form, para que o usuario o deixe na posição desejada?
veja o exemplo do amigo abaixo...
[quote][http://www.vbmania.com.br/pages/index.php?varModulo=Detalhe&varID=6390/quote]
[quote][http://www.vbmania.com.br/pages/index.php?varModulo=Detalhe&varID=6390/quote]
é 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?
alguem mais pode me ajudar?
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
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
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...
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...
deu quase certoquando eu clico e arrasto, a borda se move, mas depois quando solto o clique a imagem fika no mesmo lugar
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
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