Usercontrol.ctl about Webbrowser GIF(PNG ,JPG),Support Url,Localdisk File
[gif ocx,Png ocx] activex control
Code:
Dim WithEvents M_Dom As MSHTML.HTMLDocument
Public Event ImgClick()
Private Url As String
'Usercontrol Name:WebImgOcx
Private Sub UserControl_Initialize()
'add Webbrowser to Usercontrol
UserControl.ScaleMode = 3
WebBrowser1.Visible = False
End Sub
Public Property Get ImgUrl() As String
ImgUrl = Url
End Property
Public Property Let ImgUrl(ByVal vNewValue As String)
Url = vNewValue
If Url <> "" Then
WebBrowser1.Visible = True
SetImg Url
Else
WebBrowser1.Visible = False
End If
End Property
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
ImgUrl = PropBag.ReadProperty("ImgUrl", "")
End Sub
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
PropBag.WriteProperty "ImgUrl", ImgUrl
End Sub
Sub SetImg(UrlA As String)
Url = UrlA
WebBrowser1.Navigate Url
End Sub
Private Function M_Dom_onclick() As Boolean
RaiseEvent ImgClick
End Function
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, Url As Variant)
If Url = "" Then Exit Sub
Dim body As Object
Set M_Dom = WebBrowser1.Document
Set body = WebBrowser1.Document.body
body.Scroll = "no"
body.Style.border = "none"
body.leftMargin = 0
body.topMargin = 0
WebBrowser1.Width = body.All(0).clientWidth
WebBrowser1.Height = body.All(0).clientHeight
UserControl.Width = WebBrowser1.Width * Screen.TwipsPerPixelX
UserControl.Height = WebBrowser1.Height * Screen.TwipsPerPixelY
Call WebBrowser1.Document.parentWindow.execScript("document.body.ondragstart=function(){return false}", "javascript") 'good
Call WebBrowser1.Document.parentWindow.execScript("document.body.oncontextmenu=function(){return false}", "javascript") 'good '禁止右键
End Sub
Code:
WebImgOcx2.Imgurl="http://www.a.com/123.gif"
Private Sub WebImgOcx2_ImgClick()
MsgBox WebImgOcx2.ImgUrl
End Sub