VB6中,使用PICTRUEBox或IMAGE控件,如何让加载在其中的小图片拉伸至整个屏幕大小(当然不覆盖窗体边框、菜单栏、工具栏和状态栏的空间)。
方法有多种,总结如下:
1、用image控件
Private Sub Form_Load()
Image1.Stretch = True
End Sub
Private Sub Form_Resize()
Image1.Move 0,0,Me.ScaleWidth,Me.ScaleHeight
End Sub
2、用picture控件
用image控件很简单,但用picture控件就麻烦点
Dim TmpPic As IPictureDisp
Private Sub Picture1_Paint()
Picture1.PaintPicture TmpPic,0,Picture1.ScaleWidth,Picture1.ScaleHeight
End Sub
Private Sub Form_Load()
Set TmpPic = LoadPicture("d:/a.jpg")
End Sub
Private Sub Form_Resize()
Picture1.Move 0,Me.Width,Me.Height
Call Picture1_Paint
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set TmpPic = Nothing
End Sub
3、将你的图片放进ImageList1里
Private Sub Form_Load()
Picture1.AutoRedraw = True
End Sub
Private Sub Form_Resize()
Picture1.Move 0,Me.Height
Picture1.PaintPicture ImageList1.ListImages(1).Picture,Me.Height
End Sub
4、不用任何控件,拉伸窗体背景图
殊途同归,但是就这个问题的根本答案或者说最合理的答案是stdpicture的render方法。要想让窗体的背景随窗体大小改变而改变,无需其他控件。
a、如过你的窗体的atuoredraw属性为false,则使用一下代码:
Private BackImage As StdPicture
Private Sub Form_Load()
Set BackImage = LoadPicture("c:/1.bmp")
Me.ScaleMode = 3
End Sub
Private Sub Form_Paint()
BackImage.Render Me.hDC,Me.ScaleHeight,BackImage.Height,BackImage.Width,-BackImage.Height,ByVal 0&
End Sub
Private Sub Form_Resize()
BackImage.Render Me.hDC,ByVal 0&
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set BackImage = Nothing
End Sub
b、如果窗体的AutoRedraw属性为TRUE,则使用一下代码:
Private BackImage As StdPicture
Private Sub Form_Load()
Set BackImage = LoadPicture("c:/1.bmp")
Me.ScaleMode = 3
End Sub
Private Sub Form_Resize()
Me.Cls
BackImage.Render Me.hDC,ByVal 0&
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set BackImage = Nothing
End Sub
这个功能不建议用GDI+来做,GDI+的绘制函数比GDI的要慢很多,在resize这种事件中调用GDI+的绘图函数速度有一定问题。
原帖地址:
http://topic.csdn.net/u/20100114/09/1f33c745-1e55-4606-a133-bcc99f963267.html?87929
http://topic.csdn.net/u/20091110/16/0efe9a9b-a608-4aac-b0d8-2a109fdacd6a.html
原文链接:https://www.f2er.com/vb/262294.html