Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I capture/respond to events fired in the content of a WebBrowser control on a Windows form?

Posted on 2008-10-14
4
Medium Priority
?
208 Views
Last Modified: 2013-11-19
I am developing a Windows Smart Client application that needs to display a menu that changes based on things like the user's access, what is waiting in the user's inbox, etc..  I want the menu displayed as a list, in a hierarchical format, but without twisties or +/- symbols.  I don't even want items to expand or collapse. I used the TreeView control for the menu but it has lots of bugs when dealing with different fonts and sizes for items in the list.

So, I have chosen to use a WebBrowser control because I can easily create the HTML I need to display the menu the way I want it to look. I have added a WebBrowser control to my form. I have code that generates the HTML for the menu, writes it to a local file, then tells the WebBrowser control to navigate to that "page". This displays the menu in a all its glory, looking just the way I want it to look.

Now this "menu" contains a bunch of Div tags with text in them. Some of them are clickable links the user can click on. For example, one menu item could be "Generate Letter". When the user clicks on the <A> tag wrapping the Generate Letter text I want to be able to handle this event with code on my form.

The problem is that I can capture events raised by the WebBrowser control itself, but not the events raised by the content in that control. Is there a way to do this?


I apologize but I accidentally left the following text in the HTML in my code snippet.  The text should be removed
 
display: none

Open in new window

0
Comment
Question by:jkurant
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 

Author Comment

by:jkurant
ID: 22717810
I am Increasing the point value to encourage people to help me solve this problem.  It might be impossible, but I'm hoping not!
0
 

Author Comment

by:jkurant
ID: 22717917
The bode snipped below is the HTML for the menu I would like to display. I am also attaching a screenshot of the menu.
<HTML>
<head>
<style>
:link,:visited.:active {
 color: #000075;
 text-decoration: "none";
}
:hover {
 color: #0000FF;
 text-decoration: "underline";
}
div.AlertSection {
 font-family: Arial;
 font-size: 12pt;
 font-weight: bold;
 font-style: italic;
 color: #A00000;
 background-color: #FFFFA0;
 margin-top: 6px;
 margin-bottom: 2px;
}
div.Section {
 font-family: Arial;
 font-size: 11pt;
 font-weight: bold;
 font-style: italic;
 color: #000080;
 background-color: #E0E0FF;
 margin-top: 6px;
 margin-bottom: 2px;
}
A.B {
 color: #00007F;
 font-family: Arial narrow;
 font-size: 9pt;
 font-weight: normal;
 font-style: normal;
 margin-left: 15px;
 text-decoration: "none";
 overflow-x: "hidden";
}
</style>
</head>
 
<body>
 
<div style="display: none">
<div class="AlertSection">Action Required</div>
<a class="B" href="">XYZ Industries - created 9-22-08 (Send to CRINT failed)</a><br>
<a class="B" href="">Targét Slightly Upscale - Approved 10-07-08 (Patriot Act pending)</a><br>
</div>
 
<div class="AlertSection">Awaiting your approval - overdue</div>
<a class="B" href=""><font color=>ABC Holdings, Inc. - created 10-08-08 (Draft Complete)</font></a><br>
<a class="B" href="">Cygnus Enterprises - completed 9-29-08 (Complete)</a><br>
 
<div class="Section">Awaiting your approval</div>
<a class="B" href=""><font color=red>ABC Holdings, Inc. - created 10-08-08 (Draft Complete)</font></a><br>
<a class="B" href="">Cygnus Enterprises - completed 9-29-08 (Complete)</a><br>
 
<div class="Section">Start a new ...</div>
<a class="B" href="">Deal</a><br>
<a class="B" href="">Streamlined deal</a><br>
<a class="B" href="">Amendment</a><br>
<a class="B" href="">Line of credit extension</a><br>
 
 
<div class="Section">Find deals</div>
<a class="B" href="">My most recent deals</a><br>
<a class="B" href="">Search by name of interested party</a><br>
<a class="B" href="">Search by date & status</a><br>
 
<div class="Section">Request a report</div>
<a class="B" href="">Risk rating report</a><br>
<a class="B" href="">TAR report</a><br>
<a class="B" href="">Compliance report</a><br>
<a class="B" href="">Other report</a><br>
 
</body>
</HTML>

Open in new window

Menu---pretty.jpg
Menu-as-TreeView--left-panel-.jpg
0
 
LVL 18

Accepted Solution

by:
armoghan earned 2000 total points
ID: 22728303
On document complete you can keep the reference of the document object and add click event to it..

Here is a similar solution
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_23582209.html
0
 

Author Closing Comment

by:jkurant
ID: 31506090
That is exactly what I needed.  I'm still trying to figure out why I could not find it myself, as the solution was already on the Experts Exchange. Thank you!
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question