Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / February 2006

Tip: Looking for answers? Try searching our database.

Capture key events from hosted WebBrowser control

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Vinayak  Kamat - 20 Feb 2006 18:16 GMT
The .Net 2.0's webbrowser control is neat and pretty.
But I am not able to capture Key events when the focus is on the
webbrowser control in my winform.
Options tried.
1. Wrote a class which extends this WebBrowser and override its onkeyup
event - didn't work.
2. Same as option 1 but override preprocessmessage - didn't work.
3. Same as option 1 but override WndProc - doesn't capture any key
events happening in the browser.

Nothing works.

Can someone help me here. Would be gr8 if u can solve this.

Thanks in advance,
Vin
Charles Law - 21 Feb 2006 18:55 GMT
Hi Vin

The V2.0 WebBrowser control is the same old mshtml / shdocvw under the
covers, so I think you will have to do it the age old way. In the
DocumentComplete event, do the following

<snip>
       Private m_DocEvents2Cookie As Integer = -1    ' make this a member
variable

       ...

       Dim icp As ComTypes.IConnectionPoint = Nothing
       Dim icpc As ComTypes.IConnectionPointContainer
       Dim g As Guid

       g = GetType(mshtml.HTMLDocumentEvents2).GUID

       icpc = DirectCast(WebBrowser1.Document.DomDocument,
ComTypes.IConnectionPointContainer)

       icpc.FindConnectionPoint(g, icp)

       If m_DocEvents2Cookie <> -1 Then
           icp.Unadvise(m_DocEvents2Cookie)

           m_DocEvents2Cookie = -1
       End If

       icp.Advise(New DocumentEvents2, m_DocEvents2Cookie)
</snip>

where DocumentEvents2 is a class that you create that implements
mshtml.HTMLDocumentEvents2. The onkeyup event in your class will then fire.

HTH

Charles

> The .Net 2.0's webbrowser control is neat and pretty.
> But I am not able to capture Key events when the focus is on the
[quoted text clipped - 12 lines]
> Thanks in advance,
> Vin

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.