Private Sub axWebBrowser1_BeforeNavigate2(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_BeforeNavigate2Event)
Dim doc As IHTMLDocument2 = TryCast(Me.axWebBrowser1.Document, IHTMLDocument2)
If doc.designMode = "On" Then
'Get the url.
Dim url As String = TryCast(e.uRL, String)
If File.Exists(url) Then
'If it is a file, try to load the image.
Dim img As Image = Image.FromFile(url)
If img IsNot Nothing Then
'if it is an image, copy it to the dir of the html document.
Dim name As String = Path.GetFileName(url)
Dim dir As String = Path.GetDirectoryName("C:Usersv-shunliDownloadstest.html")
Dim path__1 As String = (dir & "") + name
img.Save(path__1)
'Get the selected range.
Dim range As IHTMLTxtRange = TryCast(doc.selection.createRange(), IHTMLTxtRange)
'Move selection to the mouse point.
Dim elementPosition As Point = Me.axWebBrowser1.PointToClient(Control.MousePosition)
range.moveToPoint(elementPosition.X, elementPosition.Y)
'Add the image element.
range.pasteHTML(String.Format("<img src=""{0}""/>", path__1))
'Stop navigating to the image.
e.cancel = True
End If
End If
End If
End Sub
引文来源 AxWebBrowser drag-drop image file to insert instead of navigating