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 / Languages / C# / December 2007

Tip: Looking for answers? Try searching our database.

WebBrowser Control - Which element was clicked

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bill - 06 Dec 2007 14:36 GMT
I have a form with a WebBrowser control. In the DocumentComplete event I add
an OnClick handler for each link found in the document. The OnClick for each
link calls the same handler function.

The events fire and this works great. The problem I have is determining
which link was clicked.

I would like to be able to get an instance of the specific HTMLElement
object that was clicked in the handler function.

The toElement and srcElement properties of the HtmlElementEventArgs object
are always null.

I would appreciate any ideas.

private void webBrowser_DocumentCompleted(object sender,
WebBrowserDocumentCompletedEventArgs e)
{
           HtmlElementCollection tags = webBrowser.Document.Links;
           foreach(HtmlElement element in tags)            
                       element.Click += new
HtmlElementEventHandler(element_Click);
}

void element_Click(object sender, HtmlElementEventArgs e)
{
       HTMLElement ClickedElement = ?????
}
Signature

Bill

Nicholas Paldino [.NET/C# MVP] - 06 Dec 2007 16:06 GMT
Bill,

   Well, the element that is clicked is the sender parameter, you just have
to cast it to an HTMLElement and viola.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

>I have a form with a WebBrowser control. In the DocumentComplete event I
>add
[quoted text clipped - 26 lines]
>        HTMLElement ClickedElement = ?????
> }
Bill - 06 Dec 2007 16:16 GMT
Too easy for me... Thank you

Signature

Bill

> Bill,
>
[quoted text clipped - 31 lines]
> >        HTMLElement ClickedElement = ?????
> > }
Peter Bromberg [C# MVP] - 06 Dec 2007 20:22 GMT
Another violin player! A viola is a musical instrument. The expression which
means “behold!” is voilà - meaning “look there!, from the French.
:-)

Site: www.eggheadcafe.com 
UnBlog: petesbloggerama.blogspot.com
Metafinder: www.blogmetafinder.com

> Bill,
>
[quoted text clipped - 31 lines]
> >        HTMLElement ClickedElement = ?????
> > }

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.