VERSION 5.00 Begin VB.Form Form1 BackColor = &H00404000& Caption = "Form1" ClientHeight = 12255 ClientLeft = 1770 ClientTop = 2025 ClientWidth = 21735 LinkTopic = "Form1" ScaleHeight = 817 ScaleMode = 3 'Pixel ScaleWidth = 1449 Begin VB.PictureBox C1 Appearance = 0 'Flat AutoSize = -1 'True BackColor = &H80000005& BorderStyle = 0 'None ForeColor = &H80000008& Height = 105 Index = 7 Left = 2160 MousePointer = 8 'Size NW SE Picture = "FormChat6d.frx":0000 ScaleHeight = 105 ScaleWidth = 105 TabIndex = 19 Top = 10800 Width = 105 End Begin VB.PictureBox C1 Appearance = 0 'Flat AutoSize = -1 'True BackColor = &H80000005& BorderStyle = 0 'None ForeColor = &H80000008& Height = 105 Index = 6 Left = 2160 MousePointer = 7 'Size N S Picture = "FormChat6d.frx":00EA ScaleHeight = 105 ScaleWidth = 105 TabIndex = 18 Top = 10620 Width = 105 End Begin VB.PictureBox C1 Appearance = 0 'Flat AutoSize = -1 'True BackColor = &H80000005& BorderStyle = 0 'None ForeColor = &H80000008& Height = 105 Index = 5 Left = 2160 MousePointer = 6 'Size NE SW Picture = "FormChat6d.frx":01D4 ScaleHeight = 105 ScaleWidth = 105 TabIndex = 17 Top = 10440 Width = 105 End Begin VB.PictureBox C1 Appearance = 0 'Flat AutoSize = -1 'True BackColor = &H80000005& BorderStyle = 0 'None ForeColor = &H80000008& Height = 105 Index = 4 Left = 2160 MousePointer = 9 'Size W E Picture = "FormChat6d.frx":02BE ScaleHeight = 105 ScaleWidth = 105 TabIndex = 16 Top = 10260 Width = 105 End Begin VB.PictureBox C1 Appearance = 0 'Flat AutoSize = -1 'True BackColor = &H80000005& BorderStyle = 0 'None ForeColor = &H80000008& Height = 105 Index = 3 Left = 2160 MousePointer = 9 'Size W E Picture = "FormChat6d.frx":03A8 ScaleHeight = 105 ScaleWidth = 105 TabIndex = 15 Top = 10080 Width = 105 End Begin VB.PictureBox C1 Appearance = 0 'Flat AutoSize = -1 'True BackColor = &H80000005& BorderStyle = 0 'None ForeColor = &H80000008& Height = 105 Index = 2 Left = 2160 MousePointer = 6 'Size NE SW Picture = "FormChat6d.frx":0492 ScaleHeight = 105 ScaleWidth = 105 TabIndex = 14 Top = 9900 Width = 105 End Begin VB.PictureBox C1 Appearance = 0 'Flat AutoSize = -1 'True BackColor = &H80000005& BorderStyle = 0 'None ForeColor = &H80000008& Height = 105 Index = 1 Left = 2160 MousePointer = 7 'Size N S Picture = "FormChat6d.frx":057C ScaleHeight = 105 ScaleWidth = 105 TabIndex = 13 Top = 9720 Width = 105 End Begin VB.PictureBox C1 Appearance = 0 'Flat AutoSize = -1 'True BackColor = &H80000005& BorderStyle = 0 'None ForeColor = &H80000008& Height = 105 Index = 0 Left = 2160 MousePointer = 8 'Size NW SE Picture = "FormChat6d.frx":0666 ScaleHeight = 105 ScaleWidth = 105 TabIndex = 12 Top = 9540 Width = 105 End Begin VB.PictureBox B1 Appearance = 0 'Flat AutoSize = -1 'True BackColor = &H80000005& BorderStyle = 0 'None ForeColor = &H80000008& Height = 105 Index = 7 Left = 1860 MousePointer = 8 'Size NW SE Picture = "FormChat6d.frx":0750 ScaleHeight = 105 ScaleWidth = 105 TabIndex = 3 Top = 10800 Width = 105 End Begin VB.PictureBox B1 Appearance = 0 'Flat AutoSize = -1 'True BackColor = &H80000005& BorderStyle = 0 'None ForeColor = &H80000008& Height = 105 Index = 6 Left = 1860 MousePointer = 7 'Size N S Picture = "FormChat6d.frx":083A ScaleHeight = 105 ScaleWidth = 105 TabIndex = 4 Top = 10620 Width = 105 End Begin VB.PictureBox B1 Appearance = 0 'Flat AutoSize = -1 'True BackColor = &H80000005& BorderStyle = 0 'None ForeColor = &H80000008& Height = 105 Index = 5 Left = 1860 MousePointer = 6 'Size NE SW Picture = "FormChat6d.frx":0924 ScaleHeight = 105 ScaleWidth = 105 TabIndex = 5 Top = 10440 Width = 105 End Begin VB.PictureBox B1 Appearance = 0 'Flat AutoSize = -1 'True BackColor = &H80000005& BorderStyle = 0 'None ForeColor = &H80000008& Height = 105 Index = 4 Left = 1860 MousePointer = 9 'Size W E Picture = "FormChat6d.frx":0A0E ScaleHeight = 105 ScaleWidth = 105 TabIndex = 6 Top = 10260 Width = 105 End Begin VB.PictureBox B1 Appearance = 0 'Flat AutoSize = -1 'True BackColor = &H80000005& BorderStyle = 0 'None ForeColor = &H80000008& Height = 105 Index = 3 Left = 1860 MousePointer = 9 'Size W E Picture = "FormChat6d.frx":0AF8 ScaleHeight = 105 ScaleWidth = 105 TabIndex = 7 Top = 10080 Width = 105 End Begin VB.PictureBox B1 Appearance = 0 'Flat AutoSize = -1 'True BackColor = &H80000005& BorderStyle = 0 'None ForeColor = &H80000008& Height = 105 Index = 2 Left = 1860 MousePointer = 6 'Size NE SW Picture = "FormChat6d.frx":0BE2 ScaleHeight = 105 ScaleWidth = 105 TabIndex = 8 Top = 9900 Width = 105 End Begin VB.PictureBox B1 Appearance = 0 'Flat AutoSize = -1 'True BackColor = &H80000005& BorderStyle = 0 'None ForeColor = &H80000008& Height = 105 Index = 1 Left = 1860 MousePointer = 7 'Size N S Picture = "FormChat6d.frx":0CCC ScaleHeight = 105 ScaleWidth = 105 TabIndex = 9 Top = 9720 Width = 105 End Begin VB.PictureBox B1 Appearance = 0 'Flat AutoSize = -1 'True BackColor = &H80000005& BorderStyle = 0 'None ForeColor = &H80000008& Height = 105 Index = 0 Left = 1860 MousePointer = 6 'Size NE SW Picture = "FormChat6d.frx":0DB6 ScaleHeight = 105 ScaleWidth = 105 TabIndex = 10 Top = 9540 Width = 105 End Begin VB.PictureBox Picture1 Appearance = 0 'Flat BackColor = &H00000040& ForeColor = &H80000008& Height = 8895 Left = 300 ScaleHeight = 591 ScaleMode = 3 'Pixel ScaleWidth = 1263 TabIndex = 11 Top = 300 Width = 18975 Begin VB.Image P1 Height = 7680 Left = 5940 Picture = "FormChat6d.frx":0EA0 Stretch = -1 'True Top = 420 Width = 7680 End Begin VB.Image P2 Height = 8865 Left = 0 Picture = "FormChat6d.frx":17250 Stretch = -1 'True Top = 0 Width = 20700 End Begin VB.Shape Shape1 BorderColor = &H0080C0FF& BorderStyle = 3 'Dot Height = 3255 Left = 1740 Top = 1560 Width = 3135 End Begin VB.Shape Shape2 BorderColor = &H0080C0FF& BorderStyle = 3 'Dot Height = 3255 Left = 1080 Top = 1500 Width = 3135 End End Begin VB.CheckBox Check1 Caption = "Block Ratio" Height = 255 Left = 11160 TabIndex = 2 Top = 9780 Width = 1215 End Begin VB.CommandButton Command2 Caption = "Real Size" Height = 795 Left = 8640 TabIndex = 1 Top = 9480 Width = 2235 End Begin VB.CommandButton Command1 Caption = "Guardar" Height = 495 Left = 6540 TabIndex = 0 Top = 9600 Width = 1755 End Begin VB.Line Line2 X1 = 0 X2 = 12105 Y1 = 9960 Y2 = 9960 End Begin VB.Line Line1 X1 = 0 X2 = 12105 Y1 = 4080 Y2 = 4080 End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False ' Declaraciones Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long Private Type POINTAPI X As Long Y As Long End Type Dim ImageIndex(1) As Integer Dim ResizeEdge(1) As String Dim ptInicio(1) As POINTAPI Dim ptActual(1) As POINTAPI Dim ptInicioImg(1) As POINTAPI Dim ptActualImg(1) As POINTAPI Dim ptActualImgPrev(1) As POINTAPI Dim ImageOriLeft(1) As Long Dim ImageOriTop(1) As Long Dim ImageRealWidth(1) As Long Dim ImageRealHeight(1) As Long Dim aspectRatio(1) As Double ' Relación de aspecto original (ancho/alto) Dim IsMoving(1) As Boolean Dim IsResizing(1) As Boolean Dim MouseOffsetX(1) As Long Dim MouseOffsetY(1) As Long Dim StartX(1) As Long Dim StartY(1) As Long Dim StartWidth(1) As Long Dim StartHeight(1) As Long Private Sub Command1_Click() UpdateResizeAreasP1 End Sub Private Sub Command2_Click() P1.Width = ImageRealWidth(0) P1.Height = ImageRealHeight(0) P1.Left = 150 P1.Top = 100 UpdateResizeAreasP1 End Sub Private Sub Form_Load() 'InitGDIPlus 'ImagePath1$ = App.Path & "\copie-espacio-mesa-madera-decoracion-sobre-oficina-casa-oscura-borrosa-fondo_67155-28777.jpg" 'P2.Picture = LoadPictureGDIPlus(ImagePath1$, , , vbWhite) 'P2.Picture = LoadPictureGDIPlus(App.Path & "\copie-espacio-mesa-madera-decoracion-sobre-oficina-casa-oscura-borrosa-fondo_67155-28777.jpg", 1380, 591, vbBlack, False) 'P1.Picture = LoadPictureGDIPlus(App.Path & "\alina vestido azul dorado char20000_nobg.png") 'P1.Aspect = 1 P1.Picture = LoadPicture("C:\alinaazuldorado.jpg") P2.Picture = LoadPicture("C:\fondo.jpg") P1.Left = 420 P1.Top = 24 ImageOriLeft(0) = P1.Left ImageOriTop(0) = P1.Top ImageRealWidth(0) = P1.Width ImageRealHeight(0) = P1.Height If ImageRealHeight(0) <> 0 Then aspectRatio(0) = ImageRealWidth(0) / ImageRealHeight(0) End If ImageOriLeft(1) = P2.Left ImageOriTop(1) = P2.Top ImageRealWidth(1) = P2.Width ImageRealHeight(1) = P2.Height If ImageRealHeight(1) <> 0 Then aspectRatio(1) = ImageRealWidth(1) / ImageRealHeight(1) End If UpdateResizeAreasP1 UpdateResizeAreasP2 End Sub Private Sub P1_Paint() 'P1.Cls 'P1.PaintPicture P1.Picture, 0, 0, P1.ScaleWidth, P1.ScaleHeight End Sub ' Manejador para iniciar movimiento (arrastrar) del PictureBox principal Private Sub P1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbLeftButton Then P1.MousePointer = vbSizeAll ' Capturamos la posición global del ratón en el momento del MouseDown ptInicioImg(0) = ObtenerCursorScreen() ptActualImgPrev(0) = ptInicioImg(0) IsMoving(0) = True IsResizing(0) = False End If End Sub ' Manejador para movimiento del PictureBox principal Private Sub P1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If IsMoving(0) Then ' Obtenemos la posición global actual del ratón ptActualImg(0) = ObtenerCursorScreen() If ptActualImg(0).X <> ptActualImgPrev(0).X Or ptActualImg(0).Y <> ptActualImgPrev(0).Y Then ' Calculamos la diferencia de posición Dim difXImg As Long, difYImg As Long difXImg = ptActualImg(0).X - ptInicioImg(0).X difYImg = ptActualImg(0).Y - ptInicioImg(0).Y ' Actualizamos la posición del PictureBox (lo movemos) P1.Left = ImageOriLeft(0) + difXImg P1.Top = ImageOriTop(0) + difYImg ' Actualizamos la posición de los controladores de tamaño (C1) UpdateResizeAreasP1 ' Actualizamos la posición previa ptActualImgPrev(0) = ptActualImg(0) End If End If End Sub ' Manejador para finalizar movimiento del PictureBox principal Private Sub P1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) P1.MousePointer = vbDefault IsMoving(0) = False ' Guardamos la posición final como origen para futuros movimientos ImageOriLeft(0) = P1.Left ImageOriTop(0) = P1.Top End Sub ' Manejador para iniciar redimensionamiento (MouseDown en controladores de esquina/lado) Private Sub C1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbLeftButton Then ' Guardamos el índice del controlador que se presionó ImageIndex(0) = Index ptInicio(0) = ObtenerCursorScreen() MouseOffsetX(0) = X MouseOffsetY(0) = Y StartX(0) = P1.Left StartY(0) = P1.Top StartWidth(0) = P1.Width StartHeight(0) = P1.Height ' Determinamos qué borde está siendo ajustado según el índice del PictureBox C1 Select Case ImageIndex(0) Case 0 ' Arriba-izquierda ResizeEdge(0) = "TopLeft" Case 1 ' Arriba-central ResizeEdge(0) = "TopCenter" Case 2 ' Arriba-derecha ResizeEdge(0) = "TopRight" Case 3 ' Medio-izquierda ResizeEdge(0) = "LeftCenter" Case 4 ' Medio-derecha ResizeEdge(0) = "RightCenter" Case 5 ' Abajo-izquierda ResizeEdge(0) = "BottomLeft" Case 6 ' Abajo-central ResizeEdge(0) = "BottomCenter" Case 7 ' Abajo-derecha ResizeEdge(0) = "BottomRight" End Select End If End Sub ' Manejador para redimensionamiento mientras se arrastra un controlador (MouseMove en C1) Private Sub C1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single) If ResizeEdge(0) <> "" Then ' Recalcular las diferencias de posición (en píxeles) desde el inicio del arrastre ptActual(0) = ObtenerCursorScreen() Dim DiffX%: DiffX% = ptActual(0).X - ptInicio(0).X Dim DiffY%: DiffY% = ptActual(0).Y - ptInicio(0).Y ' Según el borde/corner que se está redimensionando, aplicamos lógica Select Case ResizeEdge(0) Case "TopLeft" If Check1.Value = vbChecked Then ' Bloquear proporción activado ' Bloqueo de ratio: ajustar ancho/alto manteniendo proporción ' Determinar eje predominante del movimiento (horizontal vs vertical) If Abs(DiffY%) * ImageRealWidth(0) < Abs(DiffX%) * ImageRealHeight(0) Then ' Limitado por movimiento vertical (altura controla) newH = StartHeight(0) - DiffY% newW = CLng(newH * aspectRatio(0)) Else ' Limitado por movimiento horizontal (anchura controla) newW = StartWidth(0) - DiffX% newH = CLng(newW / aspectRatio(0)) End If ' Asegurar tamaño mínimo de 50x50 píxeles If newW < 50 Then newW = 50 newH = CLng(newW / aspectRatio(0)) End If If newH < 50 Then newH = 50 newW = CLng(newH * aspectRatio(0)) End If ' Aplicar nuevos valores de posición y tamaño ' (esquina inferior derecha fija) P1.Left = StartX(0) + (StartWidth(0) - newW) P1.Top = StartY(0) + (StartHeight(0) - newH) P1.Width = newW P1.Height = newH Else ' Lógica original (sin bloquear proporción) If P1.Width >= 50 And StartWidth(0) - DiffX% > 0 And StartX(0) + DiffX% < ImageOriLeft(0) + ImageRealWidth(0) - 50 Then P1.Left = StartX(0) + DiffX% P1.Width = StartWidth(0) - DiffX% End If If P1.Height >= 50 And StartHeight(0) - DiffY% > 0 And StartY(0) + DiffY% < ImageOriTop(0) + ImageRealHeight(0) - 50 Then P1.Top = StartY(0) + DiffY% P1.Height = StartHeight(0) - DiffY% End If End If Case "TopCenter" If Check1.Value = vbChecked Then ' Bloquear proporción activado ' Bloqueo de ratio: ajustar ancho en proporción al cambio de alto newH = StartHeight(0) - DiffY% newW = CLng(newH * aspectRatio(0)) ' Asegurar tamaño mínimo de 50x50 píxeles If newH < 50 Then newH = 50 newW = CLng(newH * aspectRatio(0)) End If If newW < 50 Then newW = 50 newH = CLng(newW / aspectRatio(0)) End If ' Aplicar nuevos valores de posición y tamaño ' (borde inferior fijo) P1.Top = StartY(0) + (StartHeight(0) - newH) P1.Width = newW P1.Height = newH Else ' Lógica original (sin bloquear proporción) If P1.Height >= 50 And StartHeight(0) + DiffY% > 0 And StartY(0) + DiffY% < ImageOriTop(0) + ImageRealHeight(0) - 50 Then P1.Height = StartHeight(0) + DiffY% End If End If Case "TopRight" If Check1.Value = vbChecked Then ' Bloquear proporción activado If Abs(DiffY%) * ImageRealWidth(0) < Abs(DiffX%) * ImageRealHeight(0) Then ' Altura controla newH = StartHeight(0) - DiffY% newW = CLng(newH * aspectRatio(0)) Else ' Anchura controla newW = StartWidth(0) + DiffX% newH = CLng(newW / aspectRatio(0)) End If If newW < 50 Then newW = 50: newH = CLng(newW / aspectRatio(0)) End If If newH < 50 Then newH = 50: newW = CLng(newH * aspectRatio(0)) End If P1.Top = StartY(0) + (StartHeight(0) - newH) P1.Width = newW: P1.Height = newH Else If P1.Width >= 50 And StartWidth(0) + DiffX% > 0 And StartX(0) + DiffX% < ImageOriLeft(0) + ImageRealWidth(0) - 50 Then P1.Width = StartWidth(0) + DiffX% End If If P1.Height >= 50 And StartHeight(0) - DiffY% > 0 And StartY(0) + DiffY% < ImageOriTop(0) + ImageRealHeight(0) - 50 Then P1.Top = StartY(0) + DiffY% P1.Height = StartHeight(0) - DiffY% End If End If Case "LeftCenter" If Check1.Value = vbChecked Then ' Bloquear proporción activado newW = StartWidth(0) - DiffX% newH = CLng(newW / aspectRatio(0)) If newW < 50 Then newW = 50: newH = CLng(newW / aspectRatio(0)) End If If newH < 50 Then newH = 50: newW = CLng(newH * aspectRatio(0)) End If P1.Left = StartX(0) + (StartWidth(0) - newW) P1.Width = newW: P1.Height = newH Else If P1.Width >= 50 And StartWidth(0) - DiffX% > 0 And StartX(0) + DiffX% < ImageOriLeft(0) + ImageRealWidth(0) - 50 Then P1.Left = StartX(0) + DiffX% P1.Width = StartWidth(0) - DiffX% End If End If Case "RightCenter" If Check1.Value = vbChecked Then ' Bloquear proporción activado newW = StartWidth(0) + DiffX% newH = CLng(newW / aspectRatio(0)) If newW < 50 Then newW = 50: newH = CLng(newW / aspectRatio(0)) End If If newH < 50 Then newH = 50: newW = CLng(newH * aspectRatio(0)) End If P1.Width = newW: P1.Height = newH Else If P1.Width >= 50 And StartWidth(0) + DiffX% > 0 Then P1.Width = StartWidth(0) + DiffX% End If End If Case "BottomLeft" If Check1.Value = vbChecked Then ' Bloquear proporción activado If Abs(DiffY%) * ImageRealWidth(0) < Abs(DiffX%) * ImageRealHeight(0) Then newH = StartHeight(0) + DiffY% newW = CLng(newH * aspectRatio(0)) Else newW = StartWidth(0) - DiffX% newH = CLng(newW / aspectRatio(0)) End If If newW < 50 Then newW = 50: newH = CLng(newW / aspectRatio(0)) End If If newH < 50 Then newH = 50: newW = CLng(newH * aspectRatio(0)) End If P1.Left = StartX(0) + (StartWidth(0) - newW) P1.Width = newW: P1.Height = newH Else If P1.Width >= 50 And StartWidth(0) - DiffX% > 0 And StartX(0) + DiffX% < ImageOriLeft(0) + ImageRealWidth(0) - 50 Then P1.Left = StartX(0) + DiffX% P1.Width = StartWidth(0) - DiffX% End If If P1.Height >= 50 And StartHeight(0) + DiffY% > 0 Then P1.Height = StartHeight(0) + DiffY% End If End If Case "BottomCenter" If Check1.Value = vbChecked Then ' Bloquear proporción activado newH = StartHeight(0) + DiffY% newW = CLng(newH * aspectRatio(0)) If newH < 50 Then newH = 50: newW = CLng(newH * aspectRatio(0)) End If If newW < 50 Then newW = 50: newH = CLng(newW / aspectRatio(0)) End If P1.Width = newW: P1.Height = newH Else If P1.Height >= 50 And StartHeight(0) + DiffY% > 0 Then P1.Height = StartHeight(0) + DiffY% End If End If Case "BottomRight" If Check1.Value = vbChecked Then ' Bloquear proporción activado If Abs(DiffY%) * ImageRealWidth(0) < Abs(DiffX%) * ImageRealHeight(0) Then ' Altura controla (movimiento vertical predominante) newH = StartHeight(0) + DiffY% newW = CLng(newH * aspectRatio(0)) Else ' Anchura controla (movimiento horizontal predominante) newW = StartWidth(0) + DiffX% newH = CLng(newW / aspectRatio(0)) End If If newW < 50 Then newW = 50 newH = CLng(newW / aspectRatio(0)) End If If newH < 50 Then newH = 50 newW = CLng(newH * aspectRatio(0)) End If P1.Width = newW P1.Height = newH Else If P1.Width >= 50 And StartWidth(0) + DiffX% > 0 And StartX(0) + DiffX% < ImageOriLeft(0) + ImageRealWidth(0) - 50 Then P1.Width = StartWidth(0) + DiffX% End If If P1.Height >= 50 And StartHeight(0) + DiffY% > 0 Then P1.Height = StartHeight(0) + DiffY% End If End If End Select ' Actualizar la posición de la forma de selección (Shape2) y controladores UpdateResizeAreasP1 End If End Sub Private Sub C1_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single) ResizeEdge(0) = "" End Sub ' Manejador para obtener las coordenadas de pantalla del cursor del ratón Private Function ObtenerCursorScreen() As POINTAPI Dim p As POINTAPI GetCursorPos p ObtenerCursorScreen = p End Function ' Manejador para iniciar movimiento del PictureBox de fondo (P2) Private Sub P2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbLeftButton Then P2.MousePointer = vbSizeAll ' Capturamos la posición global del ratón al hacer clic en el PictureBox de fondo ptInicioImg(1) = ObtenerCursorScreen() ptActualImgPrev(1) = ptInicioImg(1) IsMoving(1) = True IsResizing(1) = False End If End Sub ' Manejador para movimiento del PictureBox de fondo (P2) Private Sub P2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If IsMoving(1) Then ' Obtenemos la posición global actual del ratón ptActualImg(1) = ObtenerCursorScreen() If ptActualImg(1).X <> ptActualImgPrev(1).X Or ptActualImg(1).Y <> ptActualImgPrev(1).Y Then ' Calculamos la diferencia de posición Dim difXImg As Long, difYImg As Long difXImg = ptActualImg(1).X - ptInicioImg(1).X difYImg = ptActualImg(1).Y - ptInicioImg(1).Y ' Actualizamos la posición del PictureBox de fondo P2.Left = ImageOriLeft(1) + difXImg P2.Top = ImageOriTop(1) + difYImg ' Actualizamos la posición de los controladores de tamaño (B1) UpdateResizeAreasP2 ' Actualizamos la posición previa ptActualImgPrev(1) = ptActualImg(1) End If End If End Sub ' Manejador para finalizar movimiento del PictureBox de fondo (P2) Private Sub P2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) P2.MousePointer = vbDefault IsMoving(1) = False ' Guardamos la posición final como origen para futuros movimientos ImageOriLeft(1) = P2.Left ImageOriTop(1) = P2.Top End Sub ' Manejador para iniciar redimensionamiento del PictureBox de fondo (MouseDown en B1) Private Sub B1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbLeftButton Then ' Guardamos el índice del controlador que se presionó ImageIndex(1) = Index ptInicio(1) = ObtenerCursorScreen() MouseOffsetX(1) = X MouseOffsetY(1) = Y StartX(1) = P2.Left StartY(1) = P2.Top StartWidth(1) = P2.Width StartHeight(1) = P2.Height Select Case ImageIndex(1) Case 0: ResizeEdge(1) = "TopLeft" Case 1: ResizeEdge(1) = "TopCenter" Case 2: ResizeEdge(1) = "TopRight" Case 3: ResizeEdge(1) = "LeftCenter" Case 4: ResizeEdge(1) = "RightCenter" Case 5: ResizeEdge(1) = "BottomLeft" Case 6: ResizeEdge(1) = "BottomCenter" Case 7: ResizeEdge(1) = "BottomRight" End Select End If End Sub ' Manejador para redimensionamiento mientras se arrastra un controlador (MouseMove en B1) Private Sub B1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single) If ResizeEdge(1) <> "" Then ' Recalcular las diferencias de posición (en píxeles) desde el inicio del arrastre ptActual(1) = ObtenerCursorScreen() Dim DiffX%: DiffX% = ptActual(1).X - ptInicio(1).X Dim DiffY%: DiffY% = ptActual(1).Y - ptInicio(1).Y ' Según el borde/corner que se está redimensionando, aplicamos lógica Select Case ResizeEdge(1) Case "TopLeft" If Check1.Value = vbChecked Then If Abs(DiffY%) * ImageRealWidth(1) < Abs(DiffX%) * ImageRealHeight(1) Then newH = StartHeight(1) - DiffY% newW = CLng(newH * aspectRatio(1)) Else newW = StartWidth(1) - DiffX% newH = CLng(newW / aspectRatio(1)) End If If newW < 50 Then newW = 50: newH = CLng(newW / aspectRatio(1)) End If If newH < 50 Then newH = 50: newW = CLng(newH * aspectRatio(1)) End If P2.Left = StartX(1) + (StartWidth(1) - newW) P2.Top = StartY(1) + (StartHeight(1) - newH) P2.Width = newW: P2.Height = newH Else If P2.Width >= 50 And StartWidth(1) - DiffX% > 0 And StartX(1) + DiffX% < ImageOriLeft(1) + ImageRealWidth(1) - 50 Then P2.Left = StartX(1) + DiffX% P2.Width = StartWidth(1) - DiffX% End If If P2.Height >= 50 And StartHeight(1) - DiffY% > 0 And StartY(1) + DiffY% < ImageOriTop(1) + ImageRealHeight(1) - 50 Then P2.Top = StartY(1) + DiffY% P2.Height = StartHeight(1) - DiffY% End If End If Case "TopCenter" If Check1.Value = vbChecked Then newH = StartHeight(1) - DiffY% newW = CLng(newH * aspectRatio(1)) If newH < 50 Then newH = 50: newW = CLng(newH * aspectRatio(1)) End If If newW < 50 Then newW = 50: newH = CLng(newW / aspectRatio(1)) End If P2.Top = StartY(1) + (StartHeight(1) - newH) P2.Width = newW: P2.Height = newH Else If P2.Height >= 50 And StartHeight(1) - DiffY% > 0 And StartY(1) + DiffY% < ImageOriTop(1) + ImageRealHeight(1) - 50 Then P2.Top = StartY(1) + DiffY% P2.Height = StartHeight(1) - DiffY% End If End If Case "TopRight" If Check1.Value = vbChecked Then If Abs(DiffY%) * ImageRealWidth(1) < Abs(DiffX%) * ImageRealHeight(1) Then newH = StartHeight(1) - DiffY% newW = CLng(newH * aspectRatio(1)) Else newW = StartWidth(1) + DiffX% newH = CLng(newW / aspectRatio(1)) End If If newW < 50 Then newW = 50: newH = CLng(newW / aspectRatio(1)) End If If newH < 50 Then newH = 50: newW = CLng(newH * aspectRatio(1)) End If P2.Top = StartY(1) + (StartHeight(1) - newH) P2.Width = newW: P2.Height = newH Else If P2.Width >= 50 And StartWidth(1) + DiffX% > 0 And StartX(1) + DiffX% < ImageOriLeft(1) + ImageRealWidth(1) - 50 Then P2.Width = StartWidth(1) + DiffX% End If If P2.Height >= 50 And StartHeight(1) - DiffY% > 0 And StartY(1) + DiffY% < ImageOriTop(1) + ImageRealHeight(1) - 50 Then P2.Top = StartY(1) + DiffY% P2.Height = StartHeight(1) - DiffY% End If End If Case "LeftCenter" If Check1.Value = vbChecked Then newW = StartWidth(1) - DiffX% newH = CLng(newW / aspectRatio(1)) If newW < 50 Then newW = 50: newH = CLng(newW / aspectRatio(1)) End If If newH < 50 Then newH = 50: newW = CLng(newH * aspectRatio(1)) End If P2.Left = StartX(1) + (StartWidth(1) - newW) P2.Width = newW: P2.Height = newH Else If P2.Width >= 50 And StartWidth(1) - DiffX% > 0 And StartX(1) + DiffX% < ImageOriLeft(1) + ImageRealWidth(1) - 50 Then P2.Left = StartX(1) + DiffX% P2.Width = StartWidth(1) - DiffX% End If End If Case "RightCenter" If Check1.Value = vbChecked Then newW = StartWidth(1) + DiffX% newH = CLng(newW / aspectRatio(1)) If newW < 50 Then newW = 50: newH = CLng(newW / aspectRatio(1)) End If If newH < 50 Then newH = 50: newW = CLng(newH * aspectRatio(1)) End If P2.Width = newW: P2.Height = newH Else If P2.Width >= 50 And StartWidth(1) + DiffX% > 0 Then P2.Width = StartWidth(1) + DiffX% End If End If Case "BottomLeft" If Check1.Value = vbChecked Then If Abs(DiffY%) * ImageRealWidth(1) < Abs(DiffX%) * ImageRealHeight(1) Then newH = StartHeight(1) + DiffY% newW = CLng(newH * aspectRatio(1)) Else newW = StartWidth(1) - DiffX% newH = CLng(newW / aspectRatio(1)) End If If newW < 50 Then newW = 50: newH = CLng(newW / aspectRatio(1)) End If If newH < 50 Then newH = 50: newW = CLng(newH * aspectRatio(1)) End If P2.Left = StartX(1) + (StartWidth(1) - newW) P2.Width = newW: P2.Height = newH Else If P2.Width >= 50 And StartWidth(1) - DiffX% > 0 And StartX(1) + DiffX% < ImageOriLeft(1) + ImageRealWidth(1) - 50 Then P2.Left = StartX(1) + DiffX% P2.Width = StartWidth(1) - DiffX% End If If P2.Height >= 50 And StartHeight(1) + DiffY% > 0 Then P2.Height = StartHeight(1) + DiffY% End If End If Case "BottomCenter" If Check1.Value = vbChecked Then newH = StartHeight(1) + DiffY% newW = CLng(newH * aspectRatio(1)) If newH < 50 Then newH = 50: newW = CLng(newH * aspectRatio(1)) End If If newW < 50 Then newW = 50: newH = CLng(newW / aspectRatio(1)) End If P2.Width = newW: P2.Height = newH Else If P2.Height >= 50 And StartHeight(1) + DiffY% > 0 Then P2.Height = StartHeight(1) + DiffY% End If End If Case "BottomRight" If Check1.Value = vbChecked Then If Abs(DiffY%) * ImageRealWidth(1) < Abs(DiffX%) * ImageRealHeight(1) Then newH = StartHeight(1) + DiffY% newW = CLng(newH * aspectRatio(1)) Else newW = StartWidth(1) + DiffX% newH = CLng(newW / aspectRatio(1)) End If If newW < 50 Then newW = 50 newH = CLng(newW / aspectRatio(1)) End If If newH < 50 Then newH = 50 newW = CLng(newH * aspectRatio(1)) End If P2.Width = newW P2.Height = newH Else If P2.Width >= 50 And StartWidth(1) + DiffX% > 0 And StartX(1) + DiffX% < ImageOriLeft(1) + ImageRealWidth(1) - 50 Then P2.Width = StartWidth(1) + DiffX% End If If P2.Height >= 50 And StartHeight(1) + DiffY% > 0 Then P2.Height = StartHeight(1) + DiffY% End If End If End Select ' Actualizar la posición de la forma de selección (Shape1) y controladores UpdateResizeAreasP2 End If End Sub Private Sub B1_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single) ResizeEdge(1) = "" End Sub Private Sub UpdateResizeAreasP1() Shape2.Left = P1.Left Shape2.Top = P1.Top Shape2.Width = P1.Width Shape2.Height = P1.Height Shape2.ZOrder 0 C1(0).Left = P1.Left - 7 + Picture1.Left C1(0).Top = P1.Top - 7 + Picture1.Top C1(1).Left = P1.Left + (P1.Width / 2) - 7 + Picture1.Left C1(1).Top = P1.Top - 7 + Picture1.Top C1(2).Left = P1.Left + P1.Width + Picture1.Left C1(2).Top = P1.Top - 7 + Picture1.Top C1(3).Left = P1.Left - 7 + Picture1.Left C1(3).Top = P1.Top + (P1.Height / 2) - 7 + Picture1.Top C1(4).Left = P1.Left + P1.Width + Picture1.Left C1(4).Top = P1.Top + (P1.Height / 2) - 7 + Picture1.Top C1(5).Left = P1.Left - 7 + Picture1.Left C1(5).Top = P1.Top + P1.Height + Picture1.Top C1(6).Left = P1.Left + (P1.Width / 2) - 7 + Picture1.Left C1(6).Top = P1.Top + P1.Height + Picture1.Top C1(7).Left = P1.Left + P1.Width + Picture1.Left C1(7).Top = P1.Top + P1.Height + Picture1.Top Picture1.ZOrder 1 End Sub Private Sub UpdateResizeAreasP2() DoEvents Shape1.Left = P2.Left Shape1.Top = P2.Top Shape1.Width = P2.Width Shape1.Height = P2.Height Shape1.ZOrder 0 B1(0).Left = P2.Left - 7 + Picture1.Left B1(0).Top = P2.Top - 7 + Picture1.Top B1(1).Left = P2.Left + (P2.Width / 2) - 7 + Picture1.Left B1(1).Top = P2.Top - 7 + Picture1.Top B1(2).Left = P2.Left + P2.Width + Picture1.Left B1(2).Top = P2.Top - 7 + Picture1.Top B1(3).Left = P2.Left - 7 + Picture1.Left B1(3).Top = P2.Top + (P2.Height / 2) - 7 + Picture1.Top B1(4).Left = P2.Left + P2.Width + Picture1.Left B1(4).Top = P2.Top + (P2.Height / 2) - 7 + Picture1.Top B1(5).Left = P2.Left - 7 + Picture1.Left B1(5).Top = P2.Top + P2.Height + Picture1.Top B1(6).Left = P2.Left + (P2.Width / 2) - 7 + Picture1.Left B1(6).Top = P2.Top + P2.Height + Picture1.Top B1(7).Left = P2.Left + P2.Width + Picture1.Left B1(7).Top = P2.Top + P2.Height + Picture1.Top Picture1.ZOrder 1 End Sub