tags:

views:

178

answers:

2

Hi, I am tasked with a project whereby I need to create a scaled down version of a Firebug like UI where the user can load an HTML page, and as they hover the mouse over the elements they'll be highlighted. The app will allow the users to select a table to be screen-scraped....haven't got to that part as yet.

Any advice?

Thanks

+3  A: 

Well, I haven't used the Firebug UI, but I have done exactly what you describe using the .NET 2.0 WebBrowser control in a WinForms app.

Basically I added the WebBrowser and a Timer control to the form then in the timer elapsed event, I query the mouse position using the GetCursorPos native function and use the WebBrowser.Document's (HtmlDocument class) GetElementFromPoint method (adjusting the x and y position to be relative to the browser control).

This returns whatever HtmlElement is under the mouse position. Here's the meat of the method:

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;
}

After you get the HtmlElement, you can get the InnerHTML to parse as you see fit.

Richard

ZeroBugBounce
This is a great headstart! Many thanks.
Saif Khan
A: 

I try to use this code but I retrieve an error on Win32Point (impossible find namespace) and HtmlScan (name not exist). I use vs 2008, with framework 3.5. pleeease, help me!