保持图片和图片框一致的方法 收藏

前端之家收集整理的这篇文章主要介绍了保持图片和图片框一致的方法 收藏前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

众所周知,VB的picture控件没有Stretch属性,加载在picture中的图片往往不是比picture小,就是比picture大,图片比picture小时不能充满整个picture,比picture大时图片不能完全显示。很不方便,下面的代码可以解决这个问题,给你带来方便。

'模块代码:

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,pic.Width,pic.Height,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,0
End Sub

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/SYSSZ/archive/2009/05/24/4211881.aspx

猜你在找的VB相关文章