Private Sub webSky_DownloadComplete()
On Error Resume Next
WebSky.Silent = True
Me.MousePointer = vbDefault
Dim x, CtrlRange
Dim sPath As String
sPath = App.Path
sPath = Left(sPath, InStr(sPath, vbNullChar) - 1)
If Len(sPath) > 3 Then sPath = sPath & "/"
If Trim(txtUser.Text) <> "" Then
gstrFileName = sPath & Trim(txtUser.Text) & "Code.bmp"
Else
gstrFileName = sPath & "TempCode.bmp"
End If
For Each x In WebSky.Document.All
If x.tagName = "IMG" Then
WebSky.Stop
Set CtrlRange = WebSky.Document.body.createControlRange()
CtrlRange.Add (x)
CtrlRange.execCommand ("Copy")
SavePicture Clipboard.GetData, gstrFileName
'getCodeForSky
End If
End If
Next
End Sub
On Error Resume Next
WebSky.Silent = True
Me.MousePointer = vbDefault
Dim x, CtrlRange
Dim sPath As String
sPath = App.Path
sPath = Left(sPath, InStr(sPath, vbNullChar) - 1)
If Len(sPath) > 3 Then sPath = sPath & "/"
If Trim(txtUser.Text) <> "" Then
gstrFileName = sPath & Trim(txtUser.Text) & "Code.bmp"
Else
gstrFileName = sPath & "TempCode.bmp"
End If
For Each x In WebSky.Document.All
If x.tagName = "IMG" Then
WebSky.Stop
Set CtrlRange = WebSky.Document.body.createControlRange()
CtrlRange.Add (x)
CtrlRange.execCommand ("Copy")
SavePicture Clipboard.GetData, gstrFileName
'getCodeForSky
End If
End If
Next
End Sub
这段VB代码展示了如何在Webbrowser控件中,遍历文档中的所有<img>标签,停止加载网页,将图片复制到剪贴板并保存为图片文件。用户可以输入自定义的文件名,否则默认保存为'TempCode.bmp'。
9369

被折叠的 条评论
为什么被折叠?



