Click here to Skip to main content
15,901,426 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)

In webbrowser control I am binding (Navigate) the html file.
When mouse over of any word I want to retrieve that particular word.
When Mouse Hover event I want to get the specific word where the mouse position on the Webbrowser document.
Is there any direct way to do this.

It's very urgent.

Thank's in Advanced.

1 solution

Try this create a H1 tag in your HTML file and hover the mouse on that you can see the text placed in text box

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
    public partial class Form5 : Form
        public Form5()
            webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);

        void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
            webBrowser1.Document.Body.MouseOver += new HtmlElementEventHandler(Body_MouseOver);

        void Body_MouseOver(object sender, HtmlElementEventArgs e)
            if (e.ToElement != null && e.ToElement.TagName == "H1" && e.ToElement.GetAttribute("processed") != "true")
                string[] words = e.ToElement.InnerHtml.Split(' ');
                e.ToElement.InnerHtml = "";
                for (int i = 0; i < words.Length; i++)
                    e.ToElement.InnerHtml += "<span> " + words[i] + " </span>";

                foreach (HtmlElement el in e.ToElement.GetElementsByTagName("span"))
                    el.MouseOver += new HtmlElementEventHandler(e_MouseOver);

                e.ToElement.SetAttribute("processed", "true");

        void e_MouseOver(object sender, HtmlElementEventArgs e)
            toolStripTextBox1.Text = e.ToElement.InnerText;

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900