Codigo del Form1:
Option Explicit
Private Const Ancho_Nav As Single = 3000
Private Const Alto_Nav As Single = 3000
Private Sub Form_Load()
Call Centrar_Imagen(Me, "J:\Documentos\piojos\piolho.jpg") 'acá va la ruta de la imagen
End Sub
'Redimensionado de los controles
Private Sub Form_Resize()
Dim Old_Scale As Single
Old_Scale = ScaleMode
ScaleMode = vbTwips
If WindowState = 1 Then Exit Sub
If ScaleWidth < (Screen.Width) / 5 Then
Me.Width = (Screen.Width) / 5
Posicionar
Exit Sub
End If
If ScaleHeight < Alto_Nav * 2 Then
Me.Height = Alto_Nav * 2
Posicionar
Exit Sub
End If
Posicionar
ScaleMode = Old_Scale
End Sub
Private Sub Posicionar()
On Local Error Resume Next
'Vuelve a centrar la imagen en el picture
Call Centrar_Imagen(Me, "J:\Documentos\piojos\piolho.jpg")
End Sub
Código de Module1:
Option Explicit
'Variable para almacenar la imagen
Private Pic As IPictureDisp
Sub Centrar_Imagen(Objeto As Object, Path_Imagen As String)
On Error GoTo ErrSub
Dim Ancho_Obj As Single 'Ancho en Pixeles del objeto contenedor
Dim Alto_Obj As Single 'Alto en Pixeles del objeto contenedor
Dim Old_Scale As Single 'Para lamacenar el ScaleMode del objeto
Static old_Path As String
If old_Path <> Path_Imagen Then
Set Pic = LoadPicture(Path_Imagen)
End If
With Objeto
.AutoRedraw = True
.Cls
Old_Scale = .ScaleMode
.ScaleMode = vbPixels
Ancho_Obj = .ScaleWidth
Alto_Obj = .ScaleHeight
End With
'Dibuja la imagen
Objeto.PaintPicture Pic, 0, 0, Ancho_Obj, Alto_Obj
'Restaura el ScaleMode
Objeto.ScaleMode = Old_Scale
old_Path = Path_Imagen
Exit Sub
'Error
ErrSub:
MsgBox Err.Description, vbCritical
End Sub