Red de conocimiento informático - Material del sitio web - Cómo utilizar PictureBox en VB

Cómo utilizar PictureBox en VB

En términos generales, el marco de la imagen no cambiará a medida que cambie el tamaño de la imagen, pero esto no es absoluto.

El siguiente código permite que el cuadro de imagen cambie a medida que cambia el tamaño de la imagen:

Opción explícita

Función de declaración privada GetObject Lib "gdi32" Alias ​​​​" GetObjectA" (ByVal hObject As GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long

Tipo privado BITMAP

bmType As Long

bmWidth As Long

bmHeight As Long

bmWidthBytes As Long

bmPlanes AsbmWidthBytes As Long

bmPlanes As Integer

bmBitsPixel como entero

bmBits como largo

Tipo de fin

Atenuar bm como mapa de bits

Atenuar hBmp mientras

Private Sub Command1_Click()

Imagen1.Height = bm.bmHeight * Screen.TwipsPerPixelY

Imagen1.Move (Form1.Width - Picture1.Width) / 2, ( Form1.Height - Picture1.Height) / 2

End Sub

Sub Command2_Click()

Picture1.Picture = LoadPicture(App.Path amp; " \" amp; "123.jpg")

hBmp = Imagen1.Imagen.Handle

Imagen1.Mover (Form1.Width - Imagen1.Width) / 2, (Form1.Height - Imagen1.Height ) / 2.Picture.Handle

GetObject hBmp, LenB(bm), bm

Imagen1.Width = bm.bmWidth * Screen.TwipsPerPixelX

Imagen1. Imagen1.Ancho) / 2, (Form1.Alto - Imagen1.Alto) / 2

End Sub