从Web浏览器控件获取有关鼠标悬停事件的信息 [英] Get word from Web browser control on mouse hover event

查看:100
本文介绍了从Web浏览器控件获取有关鼠标悬停事件的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在webbrowser控件中,我绑定(导航)html文件.
当鼠标悬停在任何单词上时,我要检索该特定单词.
当发生鼠标悬停事件时,我想获取特定单词,该单词在Webbrowser文档上的鼠标位置.
有没有直接的方法可以做到这一点.

非常紧急.

Hi,

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.

推荐答案

尝试执行此操作,在HTML文件中创建一个H1标签,然后将鼠标悬停在该标签上,您可以看到放置在文本框中的文本

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()
        {
            InitializeComponent();
            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;
        }


    }
}


这篇关于从Web浏览器控件获取有关鼠标悬停事件的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆