1个回答
展开全部
我也曾经遇到过这个困扰,这是我的处理方法,提供给你供参考:
在 WebBrowser1 的 DownloadComplete 事件中检测网页元素总个数,如果元素总个数发生了变化,第一次调用 Form_Resize 将控件宽度设置为比正常宽度稍少一点,然后再次调用 Form_Resize 将控件宽度设置为正常状态。
有关代码如下:
dim nCount As Long,nSmall as Boolean
Private Sub WebBrowser1_DownloadComplete()
Dim S As Long
On Error Resume Next
S = WebBrowser1.Document.All.length
If nCount = S Then exit sub
nCount = S
ctSmall = True: Call Form_Resize '将控件宽度缩小一点
ctSmall = False: Call Form_Resize '将控件宽度调整为正常状态
end sub
Private Sub Form_Resize()
Dim L As Long, T As Long, H As Long, W As Long
T=300
W = Me.ScaleWidth: H = Me.ScaleHeight - T
If ctSmall Then W = W - 30 '比正常宽度少 2 个像素
If H > 0 And W > 0 Then WebBrowser1.Move L, T, W, H
End Sub
另外,在显示新网页时,也就是调用 Navigate 方法前,应将变量 nCount 位为 0,如下所示:
nCount = 0
WebBrowser1.Navigate nURL
在 WebBrowser1 的 DownloadComplete 事件中检测网页元素总个数,如果元素总个数发生了变化,第一次调用 Form_Resize 将控件宽度设置为比正常宽度稍少一点,然后再次调用 Form_Resize 将控件宽度设置为正常状态。
有关代码如下:
dim nCount As Long,nSmall as Boolean
Private Sub WebBrowser1_DownloadComplete()
Dim S As Long
On Error Resume Next
S = WebBrowser1.Document.All.length
If nCount = S Then exit sub
nCount = S
ctSmall = True: Call Form_Resize '将控件宽度缩小一点
ctSmall = False: Call Form_Resize '将控件宽度调整为正常状态
end sub
Private Sub Form_Resize()
Dim L As Long, T As Long, H As Long, W As Long
T=300
W = Me.ScaleWidth: H = Me.ScaleHeight - T
If ctSmall Then W = W - 30 '比正常宽度少 2 个像素
If H > 0 And W > 0 Then WebBrowser1.Move L, T, W, H
End Sub
另外,在显示新网页时,也就是调用 Navigate 方法前,应将变量 nCount 位为 0,如下所示:
nCount = 0
WebBrowser1.Navigate nURL
参考资料: http://user.qzone.qq.com/32063270/blog/1251336005
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询