5个回答
展开全部
'frame本身不具备背景图片功能
'以下是我用API做的一个例子
'本来打算用LoadImage做,不过LoadPicture支持的图片格式多一点。
'frame控件没有AutoRedraw属性,所以我在Form_Paint里加了一些代码,解决了最小化窗体后图片消失的问题。(还有个问题:改变窗体大小的时候如果窗体覆盖图片区域会使图片消失,解决办法明天附上,太晚了,睡觉。)
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC 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 dwRop As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Dim fWidth As Integer, fHeight As Integer
Private Sub Form_Load()
Me.Show
DoEvents
Call FrameDImg(Frame1, "D:\壁纸\080505081302_5.jpg")
End Sub
Private Sub Form_Paint()
If Me.Width = fWidth And Me.Height = fHeight Then
DoEvents
Call FrameDImg(Frame1, "D:\壁纸\080505081302_5.jpg")
Else
fWidth = Me.Width
fHeight = Me.Height
End If
End Sub
Private Sub FrameDImg(oFrame As Object, ImgFilePath As String) 'FrameDImg(控件名称,图片文件的路径)
Dim FrmDc As Long, ImgDc As Long
Dim pBmp As IPictureDisp
Set pBmp = LoadPicture(ImgFilePath)
ImgDc = CreateCompatibleDC(0)
SelectObject ImgDc, pBmp.Handle
FrmDc = GetDC(oFrame.hwnd)
BitBlt FrmDc, 0, 0, oFrame.Width, oFrame.Height, ImgDc, 0, 0, vbSrcCopy
Set pBmp = Nothing
DeleteDC ImgDc
ReleaseDC oFrame.hwnd, FrmDc
End Sub
'以下是我用API做的一个例子
'本来打算用LoadImage做,不过LoadPicture支持的图片格式多一点。
'frame控件没有AutoRedraw属性,所以我在Form_Paint里加了一些代码,解决了最小化窗体后图片消失的问题。(还有个问题:改变窗体大小的时候如果窗体覆盖图片区域会使图片消失,解决办法明天附上,太晚了,睡觉。)
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC 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 dwRop As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Dim fWidth As Integer, fHeight As Integer
Private Sub Form_Load()
Me.Show
DoEvents
Call FrameDImg(Frame1, "D:\壁纸\080505081302_5.jpg")
End Sub
Private Sub Form_Paint()
If Me.Width = fWidth And Me.Height = fHeight Then
DoEvents
Call FrameDImg(Frame1, "D:\壁纸\080505081302_5.jpg")
Else
fWidth = Me.Width
fHeight = Me.Height
End If
End Sub
Private Sub FrameDImg(oFrame As Object, ImgFilePath As String) 'FrameDImg(控件名称,图片文件的路径)
Dim FrmDc As Long, ImgDc As Long
Dim pBmp As IPictureDisp
Set pBmp = LoadPicture(ImgFilePath)
ImgDc = CreateCompatibleDC(0)
SelectObject ImgDc, pBmp.Handle
FrmDc = GetDC(oFrame.hwnd)
BitBlt FrmDc, 0, 0, oFrame.Width, oFrame.Height, ImgDc, 0, 0, vbSrcCopy
Set pBmp = Nothing
DeleteDC ImgDc
ReleaseDC oFrame.hwnd, FrmDc
End Sub
展开全部
直接把frame放到picturebox里,然后把frame设置成不可见,picturebox的appearance设置成flat,填上背景图。岂不妙哉?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
上面的方法真烦,不如做一个image或者picturebox,设置它们的长宽,左右上下属性和你的frame一致,然后载入图片来的实在,而且省内存~~
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Frame好像只能设置背景颜色,不能设置背景图片的。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
同意楼上的,不能设图片背景
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询