Methods To keep images consistent with image Frames

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.