.NET Firebug就像UI帮助一样

时间:2008-10-05 23:11:53

标签: .net firebug

我的任务是一个项目,我需要创建一个缩小版本的Firebug,如用户可以加载HTML页面,当他们将鼠标悬停在元素上时,它们将被突出显示。该应用程序将允许用户选择一个表格进行屏幕删除....尚未到达该部分。

有什么建议吗?

由于

1 个答案:

答案 0 :(得分:3)

好吧,我没有使用过Firebug UI,但我完全按照你在WinForms应用程序中使用.NET 2.0 WebBrowser控件所描述的那样。

基本上我将WebBrowser和Timer控件添加到表单然后在timer elapsed事件中,我使用GetCursorPos本机函数查询鼠标位置并使用WebBrowser.Document(HtmlDocument类)GetElementFromPoint方法(调整x和y)相对于浏览器控件的位置。)

这将返回鼠标位置下的HtmlElement。这是方法的主要内容:

HtmlElement GetCurrentElement()
{
    if (Browser.ReadyState == WebBrowserReadyState.Complete && Browser.Document != null)
    {
        Win32Point mouseLoc = HtmlScan.Win32.Mouse.GetPosition();
        Point mouseLocation = new Point(mouseLoc.x, mouseLoc.y);
        // modify location to match offset of browser window and control position:
        mouseLocation.X = ((mouseLocation.X - 4) - this.Left) - Browser.Left;
        mouseLocation.Y = ((mouseLocation.Y - 31) - this.Top) - Browser.Top;

        HtmlElement element = Browser.Document.GetElementFromPoint(mouseLocation);

        return element;
    }

    return null;
}

获得HtmlElement后,您可以根据需要解析InnerHTML。

理查德

相关问题