WebBrowser denetimi, Visual Studio. NET'in veya önceki sürümlerinde bir Microsoft Visual Studio çalışmak için kolay bir denetimidir. Ancak, Visual Studio. NET'te WebBrowser denetiminin olayları işlemek daha zor bulabilirsiniz.
Aşağıdaki olay arabirimini çoğu belge olayların uygulamanızda tanıtıcı sunar:
Mshtml.HTMLDocumentEvents2_Event
olay işlemek için <a0></a0>, kendi alt yordamı veya Olay ortaya çıktığında arayabileceğiniz işlev oluşturmanız gerekir. Olayın harekete imza eşleşmesi gerekir. Örneğin, aşağıdaki alt yordamı, belgenin MouseOver olay işleme:
Private Sub document_onmouseover(ByVal e As mshtml.IHTMLEventObj)
olayı olay işleyicisi yerdir sonra kanca gerekir. Bir olay DocumentComplete olayından sonra dilediğiniz zaman üzerinde WebBrowser denetimi geçirilir kanca. Kanca sözdizimi şöyledir:
bu kod AddHandler ifade ça??r?r ve olay geçirilecek CType işlevini kullanır. Uygun türü (mshtml.HTMLDocumentEvents2_Event) belge</a1> nesnesine CType işlevi çevirir ve daha sonra OnMouseOver</a0> olayı, geçirilir. Ikinci parametre için adres, işleyicisinin sağlayan AddressOf deyimi Me.document_onmouseoveralt yordamı geçirildi.
Aşağıdaki örnekte, WebBrowser denetimi için http://www.microsoft.com
(http://www.microsoft.com)
gözatar. Sayfa yükler sonra örnek OnMouseOver ve OnClick olay için kanca oluşturur. Olayları ba?latmak için her örnek metni daha sonra bir liste kutusuna ekler.
Visual Studio .NET'i başlatın.
Visual Basic. NET'te yeni bir Windows uygulaması projesi oluşturma
Microsoft.mshtml bir başvuruyu projeye ekleyin.
Araç kutusunda, Genel ' i tıklatın.
Panelini açma'ı sağ tıklatıp Toolbox ' ı tıklatın.
<a0>Microsoft Web tarayıcısı</a0> onay kutusunu seçin ve Tamam ' ı tıklatın.
Araç kutusunda, Explorer ' ı çift tıklatın.
Araç, Windows Forms ' ı tıklatın ve sonra da liste kutusu denetimi çift tıklatın.
Denetimler, form üzerinde görüntülemek, kolay olacak biçimde düzenleyin.
Aşağıdaki kodu AssemblyInfo.vb en üstüne ekleyin, <a1>replace</a1> varolan alma
Add the following code between Windows Form Designer generated code and End Class in the code view of Form1.vb Public
Shared dwCookie2 As Integer
Public Sub add_list(ByVal a As Object)
ListBox1.Items.Insert(0, a)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AxWebBrowser1.Navigate2("http://www.microsoft.com")
Dim x As IEEvents = New IEEvents(AxWebBrowser1)
x.fm = Me
End Sub
Private Sub AxWebBrowser1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AxWebBrowser1.Enter
End Sub
Private Sub AxWebBrowser1_DocumentComplete(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent) Handles AxWebBrowser1.DocumentComplete
Dim doc As mshtml.HTMLDocument
doc = AxWebBrowser1.Document
AddHandler CType(doc, _
mshtml.HTMLDocumentEvents2_Event).onclick, AddressOf Document_onclick
AddHandler CType(doc, _
mshtml.HTMLDocumentEvents2_Event).onmouseover, AddressOf Document_onmouseover
End Sub
Private Sub AxWebBrowser1_BeforeNavigate2(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_BeforeNavigate2Event) Handles AxWebBrowser1.BeforeNavigate2
Dim doc As mshtml.HTMLDocument
doc = AxWebBrowser1.Document
RemoveHandler CType(doc, _
mshtml.HTMLDocumentEvents2_Event).onclick, _
AddressOf Document_onclick
RemoveHandler CType(doc, _
mshtml.HTMLDocumentEvents2_Event).onmouseover, _
AddressOf Document_onmouseover
End Sub
Private Sub Document_onmouseover(ByVal e As mshtml.IHTMLEventObj)
ListBox1.Items.Insert(0, "onMouseOver: " & _
e.srcElement.tagName.ToString())
End Sub
Private Function Document_onclick(ByVal e As mshtml.IHTMLEventObj) _
As Boolean
ListBox1.Items.Insert(0, "onClick: " & _
e.srcElement.tagName.ToString())
Return True
End Function
Add the following code after End Class
Public Class IEHTMLDocumentEvents
Implements mshtml.HTMLDocumentEvents2
Public Sub onactivate(ByVal pEvtObj As mshtml.IHTMLEventObj) Implements mshtml.HTMLDocumentEvents2.onactivate
End Sub
Public Sub onafterupdate(ByVal pEvtObj As mshtml.IHTMLEventObj) Implements mshtml.HTMLDocumentEvents2.onafterupdate
End Sub
Public Function onbeforeactivate(ByVal pEvtObj As mshtml.IHTMLEventObj) As Boolean Implements mshtml.HTMLDocumentEvents2.onbeforeactivate
Return True
End Function
Public Function onbeforedeactivate(ByVal pEvtObj As mshtml.IHTMLEventObj) As Boolean Implements mshtml.HTMLDocumentEvents2.onbeforedeactivate
Return True
End Function
Public Sub onbeforeeditfocus(ByVal pEvtObj As mshtml.IHTMLEventObj) Implements mshtml.HTMLDocumentEvents2.onbeforeeditfocus
End Sub
Public Function onbeforeupdate(ByVal pEvtObj As mshtml.IHTMLEventObj) As Boolean Implements mshtml.HTMLDocumentEvents2.onbeforeupdate
Return True
End Function
Public Sub oncellchange(ByVal pEvtObj As mshtml.IHTMLEventObj) Implements mshtml.HTMLDocumentEvents2.oncellchange
End Sub
Public Function onclick(ByVal pEvtObj As mshtml.IHTMLEventObj) As Boolean Implements mshtml.HTMLDocumentEvents2.onclick
Return True
End Function
Public Function oncontextmenu(ByVal pEvtObj As mshtml.IHTMLEventObj) As Boolean Implements mshtml.HTMLDocumentEvents2.oncontextmenu
Return True
End Function
Public Function oncontrolselect(ByVal pEvtObj As mshtml.IHTMLEventObj) As Boolean Implements mshtml.HTMLDocumentEvents2.oncontrolselect
Return True
End Function
Public Sub ondataavailable(ByVal pEvtObj As mshtml.IHTMLEventObj) Implements mshtml.HTMLDocumentEvents2.ondataavailable
End Sub
Public Sub ondatasetchanged(ByVal pEvtObj As mshtml.IHTMLEventObj) Implements mshtml.HTMLDocumentEvents2.ondatasetchanged
End Sub
Public Sub ondatasetcomplete(ByVal pEvtObj As mshtml.IHTMLEventObj) Implements mshtml.HTMLDocumentEvents2.ondatasetcomplete
End Sub
Public Function ondblclick(ByVal pEvtObj As mshtml.IHTMLEventObj) As Boolean Implements mshtml.HTMLDocumentEvents2.ondblclick
Return True
End Function
Public Sub ondeactivate(ByVal pEvtObj As mshtml.IHTMLEventObj) Implements mshtml.HTMLDocumentEvents2.ondeactivate
End Sub
Public Function ondragstart(ByVal pEvtObj As mshtml.IHTMLEventObj) As Boolean Implements mshtml.HTMLDocumentEvents2.ondragstart
Return True
End Function
Public Function onerrorupdate(ByVal pEvtObj As mshtml.IHTMLEventObj) As Boolean Implements mshtml.HTMLDocumentEvents2.onerrorupdate
Return True
End Function
Public Sub onfocusin(ByVal pEvtObj As mshtml.IHTMLEventObj) Implements mshtml.HTMLDocumentEvents2.onfocusin
End Sub
Public Sub onfocusout(ByVal pEvtObj As mshtml.IHTMLEventObj) Implements mshtml.HTMLDocumentEvents2.onfocusout
End Sub
Public Function onhelp(ByVal pEvtObj As mshtml.IHTMLEventObj) As Boolean Implements mshtml.HTMLDocumentEvents2.onhelp
Return True
End Function
Public Sub onkeydown(ByVal pEvtObj As mshtml.IHTMLEventObj) Implements mshtml.HTMLDocumentEvents2.onkeydown
End Sub
Public Function onkeypress(ByVal pEvtObj As mshtml.IHTMLEventObj) As Boolean Implements mshtml.HTMLDocumentEvents2.onkeypress
Return True
End Function
Public Sub onkeyup(ByVal pEvtObj As mshtml.IHTMLEventObj) Implements mshtml.HTMLDocumentEvents2.onkeyup
End Sub
Public Sub onmousedown(ByVal pEvtObj As mshtml.IHTMLEventObj) Implements mshtml.HTMLDocumentEvents2.onmousedown
End Sub
Public Sub onmousemove(ByVal pEvtObj As mshtml.IHTMLEventObj) Implements mshtml.HTMLDocumentEvents2.onmousemove
End Sub
Public Sub onmouseout(ByVal pEvtObj As mshtml.IHTMLEventObj) Implements mshtml.HTMLDocumentEvents2.onmouseout
End Sub
Public Sub onmouseover(ByVal pEvtObj As mshtml.IHTMLEventObj) Implements mshtml.HTMLDocumentEvents2.onmouseover
End Sub
Public Sub onmouseup(ByVal pEvtObj As mshtml.IHTMLEventObj) Implements mshtml.HTMLDocumentEvents2.onmouseup
End Sub
Public Function onmousewheel(ByVal pEvtObj As mshtml.IHTMLEventObj) As Boolean Implements mshtml.HTMLDocumentEvents2.onmousewheel
Return True
End Function
Public Sub onpropertychange(ByVal pEvtObj As mshtml.IHTMLEventObj) Implements mshtml.HTMLDocumentEvents2.onpropertychange
End Sub
Public Sub onreadystatechange(ByVal pEvtObj As mshtml.IHTMLEventObj) Implements mshtml.HTMLDocumentEvents2.onreadystatechange
End Sub
Public Sub onrowenter(ByVal pEvtObj As mshtml.IHTMLEventObj) Implements mshtml.HTMLDocumentEvents2.onrowenter
End Sub
Public Function onrowexit(ByVal pEvtObj As mshtml.IHTMLEventObj) As Boolean Implements mshtml.HTMLDocumentEvents2.onrowexit
Return True
End Function
Public Sub onrowsdelete(ByVal pEvtObj As mshtml.IHTMLEventObj) Implements mshtml.HTMLDocumentEvents2.onrowsdelete
End Sub
Public Sub onrowsinserted(ByVal pEvtObj As mshtml.IHTMLEventObj) Implements mshtml.HTMLDocumentEvents2.onrowsinserted
End Sub
Public Sub onselectionchange(ByVal pEvtObj As mshtml.IHTMLEventObj) Implements mshtml.HTMLDocumentEvents2.onselectionchange
End Sub
Public Function onselectstart(ByVal pEvtObj As mshtml.IHTMLEventObj) As Boolean Implements mshtml.HTMLDocumentEvents2.onselectstart
Return True
End Function
Public Function onstop(ByVal pEvtObj As mshtml.IHTMLEventObj) As Boolean Implements mshtml.HTMLDocumentEvents2.onstop
Return True
End Function
End Class
Public Class IEEvents
Implements SHDocVw.DWebBrowserEvents2
Public fm As Form1
Private icp As System.Runtime.InteropServices.UCOMIConnectionPoint
Private cookie As Integer = -1
Private m_ie As AxSHDocVw.AxWebBrowser
Public Sub New(ByRef ie As AxSHDocVw.AxWebBrowser)
' Call QueryInterface for IConnectionPointContainer
m_ie = ie
Dim icpc As System.Runtime.InteropServices.UCOMIConnectionPointContainer = CType(ie.GetOcx(), System.Runtime.InteropServices.UCOMIConnectionPointContainer)
' Find the connection point for the
' DWebBrowserEvents2 source interface
Dim g As Guid = GetType(SHDocVw.DWebBrowserEvents2).GUID
icpc.FindConnectionPoint(g, icp)
'Pass a pointer to the host to the connection point
icp.Advise(Me, cookie)
' Show the browser
ie.Visible = True
Dim oURL As Object = "http://www.microsoft.com"
Dim oEmpty As Object = ""
ie.Navigate2(oURL, oEmpty, oEmpty, oEmpty, oEmpty)
End Sub
Public Sub BeforeNavigate2(ByVal pDisp As Object, ByRef URL As Object, ByRef Flags As Object, ByRef TargetFrameName As Object, ByRef PostData As Object, ByRef Headers As Object, ByRef Cancel As Boolean) Implements SHDocVw.DWebBrowserEvents2.BeforeNavigate2
End Sub
Public Sub ClientToHostWindow(ByRef CX As Integer, ByRef CY As Integer) Implements SHDocVw.DWebBrowserEvents2.ClientToHostWindow
End Sub
Public Sub CommandStateChange(ByVal Command As Integer, ByVal Enable As Boolean) Implements SHDocVw.DWebBrowserEvents2.CommandStateChange
End Sub
Public Sub DocumentComplete(ByVal pDisp As Object, ByRef URL As Object) Implements SHDocVw.DWebBrowserEvents2.DocumentComplete
Dim doc As mshtml.HTMLDocument = CType(CType(pDisp, SHDocVw.IWebBrowser2).Document, mshtml.HTMLDocument)
Dim pConPtCon As System.Runtime.InteropServices.UCOMIConnectionPointContainer = CType(doc, System.Runtime.InteropServices.UCOMIConnectionPointContainer)
Dim guid As Guid = System.Type.GetType("mshtml.HTMLDocumentEvents2").GUID
Dim pConPt As System.Runtime.InteropServices.UCOMIConnectionPoint
pConPtCon.FindConnectionPoint(guid, pConPt)
Dim d As IEHTMLDocumentEvents = New IEHTMLDocumentEvents
pConPt.Advise(d, Form1.dwCookie2)
Dim iEvent As mshtml.HTMLDocumentEvents2_Event
iEvent = CType(doc, mshtml.HTMLDocumentEvents2_Event)
AddHandler iEvent.onclick, AddressOf ClickEventHandler
AddHandler iEvent.onmouseover, AddressOf MouseOverEventHandler
End Sub
Private Function ClickEventHandler(ByVal e As mshtml.IHTMLEventObj) As Boolean
fm.add_list(e.type + ":" + e.srcElement.tagName)
Return True
End Function
Private Sub MouseOverEventHandler(ByVal e As mshtml.IHTMLEventObj)
fm.add_list(e.type + ":" + e.srcElement.tagName)
End Sub
Public Sub DownloadBegin() Implements SHDocVw.DWebBrowserEvents2.DownloadBegin
End Sub
Public Sub DownloadComplete() Implements SHDocVw.DWebBrowserEvents2.DownloadComplete
End Sub
Public Sub FileDownload(ByRef Cancel As Boolean) Implements SHDocVw.DWebBrowserEvents2.FileDownload
End Sub
Public Sub NavigateComplete2(ByVal pDisp As Object, ByRef URL As Object) Implements SHDocVw.DWebBrowserEvents2.NavigateComplete2
End Sub
Public Sub NavigateError(ByVal pDisp As Object, ByRef URL As Object, ByRef Frame As Object, ByRef StatusCode As Object, ByRef Cancel As Boolean) Implements SHDocVw.DWebBrowserEvents2.NavigateError
End Sub
Public Sub NewWindow2(ByRef ppDisp As Object, ByRef Cancel As Boolean) Implements SHDocVw.DWebBrowserEvents2.NewWindow2
End Sub
Public Sub OnFullScreen(ByVal FullScreen As Boolean) Implements SHDocVw.DWebBrowserEvents2.OnFullScreen
End Sub
Public Sub OnMenuBar(ByVal MenuBar As Boolean) Implements SHDocVw.DWebBrowserEvents2.OnMenuBar
End Sub
Public Sub OnQuit() Implements SHDocVw.DWebBrowserEvents2.OnQuit
End Sub
Public Sub OnStatusBar(ByVal StatusBar As Boolean) Implements SHDocVw.DWebBrowserEvents2.OnStatusBar
End Sub
Public Sub OnTheaterMode(ByVal TheaterMode As Boolean) Implements SHDocVw.DWebBrowserEvents2.OnTheaterMode
End Sub
Public Sub OnToolBar(ByVal ToolBar As Boolean) Implements SHDocVw.DWebBrowserEvents2.OnToolBar
End Sub
Public Sub OnVisible(ByVal Visible As Boolean) Implements SHDocVw.DWebBrowserEvents2.OnVisible
End Sub
Public Sub PrintTemplateInstantiation(ByVal pDisp As Object) Implements SHDocVw.DWebBrowserEvents2.PrintTemplateInstantiation
End Sub
Public Sub PrintTemplateTeardown(ByVal pDisp As Object) Implements SHDocVw.DWebBrowserEvents2.PrintTemplateTeardown
End Sub
Public Sub PrivacyImpactedStateChange(ByVal bImpacted As Boolean) Implements SHDocVw.DWebBrowserEvents2.PrivacyImpactedStateChange
End Sub
Public Sub ProgressChange(ByVal Progress As Integer, ByVal ProgressMax As Integer) Implements SHDocVw.DWebBrowserEvents2.ProgressChange
End Sub
Public Sub PropertyChange(ByVal szProperty As String) Implements SHDocVw.DWebBrowserEvents2.PropertyChange
End Sub
Public Sub SetSecureLockIcon(ByVal SecureLockIcon As Integer) Implements SHDocVw.DWebBrowserEvents2.SetSecureLockIcon
End Sub
Public Sub StatusTextChange(ByVal Text As String) Implements SHDocVw.DWebBrowserEvents2.StatusTextChange
End Sub
Public Sub TitleChange(ByVal Text As String) Implements SHDocVw.DWebBrowserEvents2.TitleChange
End Sub
Public Sub UpdatePageStatus(ByVal pDisp As Object, ByRef nPage As Object, ByRef fDone As Object) Implements SHDocVw.DWebBrowserEvents2.UpdatePageStatus
End Sub
Public Sub WindowClosing(ByVal IsChildWindow As Boolean, ByRef Cancel As Boolean) Implements SHDocVw.DWebBrowserEvents2.WindowClosing
End Sub
Public Sub WindowSetHeight(ByVal Height As Integer) Implements SHDocVw.DWebBrowserEvents2.WindowSetHeight
End Sub
Public Sub WindowSetLeft(ByVal Left As Integer) Implements SHDocVw.DWebBrowserEvents2.WindowSetLeft
End Sub
Public Sub WindowSetResizable(ByVal Resizable As Boolean) Implements SHDocVw.DWebBrowserEvents2.WindowSetResizable
End Sub
Public Sub WindowSetTop(ByVal Top As Integer) Implements SHDocVw.DWebBrowserEvents2.WindowSetTop
End Sub
Public Sub WindowSetWidth(ByVal Width As Integer) Implements SHDocVw.DWebBrowserEvents2.WindowSetWidth
End Sub
End Class
ınternet Explorer otomatik hale getirmek için bu işlem aynıdır. Internet Explorer yerel değişken adınızı AxWebBrowser1 değiştirin.
Bu örnek, çerçeve kümeleri dikkate almaz. Bir çerçeve kümesi için gittiğinizde, hiçbir olay uygulamanızda göremeyebilirsiniz. Gerekirse uygulamanızdaki çerçeve olasılığı işlemek için kod da eklemeniz gerekir.
WebBrowser denetimi yan? s?ra yöntemleri hakkında daha fazla bilgi için özellikleri ve arabirimin WebBrowser denetimi sunar, olaylar aşağıdaki MSDN belgelerine başvurun:
ÖNEMLİ: Bu makale, bir kişi tarafından çevrilmek yerine, Microsoft makine-çevirisi yazılımı ile çevrilmiştir. Microsoft size hem kişiler tarafından çevrilmiş, hem de makine-çevrisi ile çevrilmiş makaleler sunar. Böylelikle, bilgi bankamızdaki tüm makalelere, kendi dilinizde ulaşmış olursunuz. Bununla birlikte, makine tarafından çevrilmiş makaleler mükemmel değildir. Bir yabancının sizin dilinizde konuşurken yapabileceği hatalar gibi, makale; kelime dağarcığı, söz dizim kuralları veya dil bilgisi açısından yanlışlar içerebilir. Microsoft, içeriğin yanlış çevrimi veya onun müşteri tarafından kullanımından doğan; kusur, hata veya zarardan sorumlu değildir. Microsoft ayrıca makine çevirisi yazılımını sıkça güncellemektedir.
Makalenin İngilizcesi aşağıdaki gibidir:311284
(http://support.microsoft.com/kb/311284/en-us/
)
Bu makaleyi kullanmak için ne kadar kişisel çaba harcadınız?
Çok az
Az
Orta
Fazla
Çok fazla
Bu bilgiyi geliştirmemiz için nedenleri ve bu konuda neler yapabileceğimizi paylaşın
Teşekkürler! Görüşleriniz, destek içeriğimizi geliştirmemize yardımcı olmak için kullanılmaktadır. Diğer yardım seçenekleri için, lütfen Yardım ve Destek Giriş Sayfasını ziyaret edin.