As we all know, the picture control of VB does not have the stretch attribute. The images loaded into picture are usually not smaller than picture, that is, larger than picture, and the pictures cannot be filled with the entire picture when compared with picture, the image cannot be fully displayed when it is larger than picture. It is inconvenient. The following code can solve this problem and bring convenience to you.
'Module code:
Option explicit
Private declare function GetObject lib "GDI32" alias "getobjecta" (byval hobject as long, byval ncount as long, lpobject as any) as long
Private type bitmap
Bmtype as long
Bmwidth as long
Bmheight as long
Bmwidthbytes as long
Bmplanes as integer
Bmbitspixel as integer
Bmbits as long
End type
Dim BM as bitmap
Dim hbmp as long
Public sub sametopicture (byref PIC as picturebox, byval ifilename as string)
PIC. Picture = loadpicture (ifilename)
Hbmp = pic. Picture. Handle
GetObject hbmp, lenb (BM), BM
PIC. width = BM. bmwidth * screen. twipsperpixelx
PIC. Height = BM. bmheight * screen. twipsperpixely
End sub
Public sub sametopic (byref PIC as picturebox, byval ifilename as string)
PIC. Picture = loadpicture (ifilename)
PIC. paintpicture pic. Picture, 0, 0, Pic. Width, Pic. Height, 0, 0
End sub
'Form code:
Private sub commandementclick ()
Sametopicture picture1, app. Path & "/" & "124.jpg"
Picture1.move 0, 0
End sub
Private sub command2_click ()
Sametopic picture1, app. Path & "/" & "124.jpg"
Picture1.move 0, 0
End sub