ARRASTAR O COMPONENTE IMAGE
Pessoal eu Tenho um projeto onde tenho um [Ô]PictureBox[Ô] e Dentro do [Ô]PictureBox[Ô] um [Ô]Image[Ô], gostaria de saber como posso arrastar o Componente [Ô]Image[Ô] dentro do [Ô]PictureBox[Ô] com o Mouse.
Isso pelo Executável do Programa. [Ô]VB6[Ô]
Agradeço muito!!!
Isso pelo Executável do Programa. [Ô]VB6[Ô]
Agradeço muito!!!
Adiciona uma image dentro de um picture...
Add esse codigo e ja era.
Obs Com esse codigo vc consegue Aumentar e diminuir o picture tbm. CAso nao queira essa funcao delete -a...bom é so estudar isso ae que vc consegue o que quer.
Nao esque[ô]a de fechar o topico do forum.
Abraço
Private Declare Function GetWindowLong Lib [Ô]user32[Ô] Alias [Ô]GetWindowLongA[Ô] (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib [Ô]user32[Ô] Alias [Ô]SetWindowLongA[Ô] (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetWindowPos Lib [Ô]user32[Ô] (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOZORDER = &H4
Private Const SWP_NOMOVE = &H2
Private Const SWP_FRAMECHANGED = &H20 [ô]The frame changed: send WM_NCCALCSIZE
Private Const SWP_DRAWFRAME = SWP_FRAMECHANGED
Private Const GWL_STYLE = (-16)
Private Const WS_THICKFRAME = &H40000
Function alterartamanhodaimagem(picturealterar As PictureBox)
Dim NewStyle As Long
NewStyle = GetWindowLong(picturealterar.hwnd, GWL_STYLE)
NewStyle = NewStyle Or WS_THICKFRAME
NewStyle = SetWindowLong(picturealterar.hwnd, GWL_STYLE, NewStyle)
SetWindowPos picturealterar.hwnd, hwnd, 0, 0, 0, 0, SWP_NOZORDER Or SWP_NOSIZE Or SWP_NOMOVE Or SWP_DRAWFRAME
End Function
Private Sub Form_Resize()
alterartamanhodaimagem Me.picture1
End Sub
Sub Redimencion(img As Image, Optional largura As Double, Optional altura As Double)
Dim vFator As Double
img.Stretch = False
vFator = largura / img.Width
img.Stretch = True
If img.Height * vFator > altura Then
img.Stretch = False
vFator = altura / img.Height
img.Stretch = True
ElseIf img.Width * vFator > largura Then
img.Stretch = False
vFator = largura / img.Width
img.Stretch = True
End If
img.Height = img.Height * vFator
img.Width = img.Width * vFator
img.Left = (largura / 2) - (img.Width / 2)
img.Top = (altura / 2) - (img.Height / 2)
End Sub
Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
Image1.Tag = X & [Ô]/[Ô] & Y
End If
End Sub
Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim cx As Single, cy As Single
With Image1
If Button = vbLeftButton Then
.MousePointer = vbSizeAll
If InStr(.Tag, [Ô]/[Ô]) > 0 Then
cx = Mid(.Tag, 1, InStr(.Tag, [Ô]/[Ô]) - 1)
cy = Mid(.Tag, InStr(.Tag, [Ô]/[Ô]) + 1)
Else
cx = .Width / 2
cy = .Height / 2
End If
.Move .Left - cx + X, .Top - cy + Y
Me.Caption = [Ô]Left: [Ô] & .Left & [Ô] / Top: [Ô] & .Top
Else
.MousePointer = vbDefault
End If
End With
End Sub
Private Sub picture1_Resize()
Call Redimencion(Me.Image1, Me.picture1.Width, picture1.Height)
End Sub
Add esse codigo e ja era.
Obs Com esse codigo vc consegue Aumentar e diminuir o picture tbm. CAso nao queira essa funcao delete -a...bom é so estudar isso ae que vc consegue o que quer.
Nao esque[ô]a de fechar o topico do forum.
Abraço
Private Declare Function GetWindowLong Lib [Ô]user32[Ô] Alias [Ô]GetWindowLongA[Ô] (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib [Ô]user32[Ô] Alias [Ô]SetWindowLongA[Ô] (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetWindowPos Lib [Ô]user32[Ô] (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOZORDER = &H4
Private Const SWP_NOMOVE = &H2
Private Const SWP_FRAMECHANGED = &H20 [ô]The frame changed: send WM_NCCALCSIZE
Private Const SWP_DRAWFRAME = SWP_FRAMECHANGED
Private Const GWL_STYLE = (-16)
Private Const WS_THICKFRAME = &H40000
Function alterartamanhodaimagem(picturealterar As PictureBox)
Dim NewStyle As Long
NewStyle = GetWindowLong(picturealterar.hwnd, GWL_STYLE)
NewStyle = NewStyle Or WS_THICKFRAME
NewStyle = SetWindowLong(picturealterar.hwnd, GWL_STYLE, NewStyle)
SetWindowPos picturealterar.hwnd, hwnd, 0, 0, 0, 0, SWP_NOZORDER Or SWP_NOSIZE Or SWP_NOMOVE Or SWP_DRAWFRAME
End Function
Private Sub Form_Resize()
alterartamanhodaimagem Me.picture1
End Sub
Sub Redimencion(img As Image, Optional largura As Double, Optional altura As Double)
Dim vFator As Double
img.Stretch = False
vFator = largura / img.Width
img.Stretch = True
If img.Height * vFator > altura Then
img.Stretch = False
vFator = altura / img.Height
img.Stretch = True
ElseIf img.Width * vFator > largura Then
img.Stretch = False
vFator = largura / img.Width
img.Stretch = True
End If
img.Height = img.Height * vFator
img.Width = img.Width * vFator
img.Left = (largura / 2) - (img.Width / 2)
img.Top = (altura / 2) - (img.Height / 2)
End Sub
Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
Image1.Tag = X & [Ô]/[Ô] & Y
End If
End Sub
Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim cx As Single, cy As Single
With Image1
If Button = vbLeftButton Then
.MousePointer = vbSizeAll
If InStr(.Tag, [Ô]/[Ô]) > 0 Then
cx = Mid(.Tag, 1, InStr(.Tag, [Ô]/[Ô]) - 1)
cy = Mid(.Tag, InStr(.Tag, [Ô]/[Ô]) + 1)
Else
cx = .Width / 2
cy = .Height / 2
End If
.Move .Left - cx + X, .Top - cy + Y
Me.Caption = [Ô]Left: [Ô] & .Left & [Ô] / Top: [Ô] & .Top
Else
.MousePointer = vbDefault
End If
End With
End Sub
Private Sub picture1_Resize()
Call Redimencion(Me.Image1, Me.picture1.Width, picture1.Height)
End Sub
Tópico encerrado , respostas não são mais permitidas