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