保持图片和图片框一致的方法 收藏
??????眾所周知,VB的picture控件沒有Stretch屬性,加載在picture中的圖片往往不是比picture小,就是比picture大,圖片比picture小時(shí)不能充滿整個(gè)picture,比picture大時(shí)圖片不能完全顯示。很不方便,下面的代碼可以解決這個(gè)問題,給你帶來方便。
'模塊代碼:
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
'窗體代碼:
Private Sub Command1_Click()
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
?
本文來自CSDN博客,轉(zhuǎn)載請標(biāo)明出處:http://blog.csdn.net/SYSSZ/archive/2009/05/24/4211881.aspx
總結(jié)
以上是生活随笔為你收集整理的保持图片和图片框一致的方法 收藏的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: VB中使用PNG格式图片的一种新方法
- 下一篇: ADO Execute 方法