1,451
社区成员
发帖
与我相关
我的任务
分享
Option Explicit
'Form1上添加1个图片框picture1
Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
Private Declare Function SetStretchBltMode Lib "gdi32" (ByVal hdc As Long, ByVal nStretchMode As Long) As Long
Private Const HALFTONE = 4
Private Const SRCCOPY = &HCC0020 ' (DWORD) dest = source
Private Sub Form_Load()
Picture1.Picture = LoadPicture("C:\images.jpg") '这时加入背景图,使其一运行就充满窗体
Picture1.Visible = False
Picture1.AutoRedraw = True
Me.AutoRedraw = True
Call Form_Resize
Me.Refresh
Me.AutoRedraw = False
End Sub
Private Sub Form_Resize()
Dim Rtn As Long
Dim hDC1 As Long, hDC2 As Long
hDC1 = Picture1.hdc
hDC2 = Me.hdc
Call SetStretchBltMode(hDC2, HALFTONE)
Rtn = StretchBlt(hDC2, 0, 0, Me.ScaleWidth, Me.ScaleHeight, hDC1, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, SRCCOPY)
Me.AutoRedraw = True
Me.Refresh
End Sub
Option Explicit
'增加一个 image1 控件
Private Sub Form_Load()
'image1 加载图片
Image1.Left = 0
Image1.Top = 0
'位置
Image1.Width = Me.Width
Image1.Height = Me.Height
'大小
Image1.Stretch = True
'图片随控件而改变大小
Image1.Picture = LoadPicture("C:\WINDOWS\Web\Wallpaper\Bliss.bmp")
'加载图片
End Sub
Private Sub Form_Resize()
If Me.Width > 0 And Me.Height > 0 Then '只有大于0改变背景及设置背景
Image1.Width = Me.Width
Image1.Height = Me.Height
End If
End Sub