WebBrowser control capture DHTML events
Hai (SunHai) translation
development tools: Microsoft Visual Studio. NET 2003
Operating System: Windows XP
And other controls, we can use WebBrowser control to build our Windows form application. From the toolbox, select the Windows Forms control group, click "Microsoft Web Browser", Visual Studio. NET in the background AxImp.exe tools used to create ActiveX controls, controls for the name "AxWebBrowser". In vb.net can not directly use COM components, COM are Unmanaged Code, in VB.NET in the use of these components must be completed to Unmanaged Code from Managed Code conversion.
In general, you can use the WebBrowser control, like the original, such as the method call to specify attributes, such as capture the event.
Some things are not as simple as that. We have to capture the page, such as when a user clicks on the page elements (such as the background), the page elements lead to the onclick event. Fat fruit we do not capture the event, it is necessary to raise the level of DHTML, Document Object until the highest level. In this way, we will be able to capture any of the events. In VB6, we can simply specify WithEvents Keywords WebBrowser.Document to MSHTML.HTMLDocument.
In VB.NET, this simple method is no longer valid. Because the ActiveX control to create two interfaces, both interfaces use the same method name, resulting in run-time error. Therefore, you must explicitly specify the interface Document object to use, and create event handler.
The following is a sample code:
'IMPORTANT: this code assumes that you've added a reference to the
'Microsoft HTML Object Library type library
Private Sub Form1_Load (ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
AxWebBrowser1.Navigate ( "http://localhost/default.asp")
Private Sub AxWebBrowser1_NavigateComplete2 (ByVal sender As Object, _
ByVal e As AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event) Handles _
'Must wait for this event to grab a valid refernece to the Document
Dim doc As mshtml.HTMLDocument = DirectCast (AxWebBrowser1.Document, _
'Cast to the interface that defines the event you're interested in
Dim docevents As mshtml.HTMLDocumentEvents2_Event = DirectCast (doc, _
'Define a handler to the onclick event
AddHandler docevents.onclick, AddressOf onclickproc
'Notice that the signature of this event is different from usual, as it
'Is expected to return a Boolean - if false the default effect associated
'With the event (for example, jumping to another page if the click is on
'An hyperlink) is canceled.
Private Function onclickproc (ByVal obj As mshtml.IHTMLEventObj) As Boolean
'An object on the page has been clicked - you can learn more about
'Type and position of this object by querying the obj's properties
This is my first translation.
Personal experience, the past few days in foreign countries around the procedure site design, benefited a lot from listening. Learning calligraphy think "should follow the best." Sharing of software lies in the international. Software design of the study is it not so? International Learning Resources Learning Resources, compared to domestic?
English is not the obstacles. I do not believe that my English than Hello. Middle school fundamentals, coupled with PowerWord means that translation, is sufficient.
.Net Control and components Articles
- Published Activex
- Prepared to use ActiveX Controls C # (c)
- Prepared to use ActiveX Controls C # (b)
- Prepared to use ActiveX Controls C # (a)
- C # in the use of DirectSound audio
- Visual C # to create and use ActiveX components
- NUnit in the plug-in VS.NET 2003.
- A paging control
- Real grid similar to Excel Control
- Visual Studio.NET in the use of custom plug-ins to maximize your productivity (a)
- Visual Studio.NET in the use of custom plug-ins to maximize your productivity (b)
- Visual Studio.NET in the use of custom plug-ins to maximize your productivity (c)
- Using VS.NET to create. NET components reusable database
- Can teach you a confirmation dialog pop-up custom Web server control ConfirmButton
- WebBrowser control capture DHTML events
- Introduced with a free data display / entry / update / delete function in asp.net control
- DataGrid control (a)
- Blog to your personalized calendar control to create
- . NET client applications:. NET applications updating components (2)
Can't Find What You're Looking For?
Rating: Not yet rated