2008-10-05 74 views
0

我的任务是一个项目,我需要创建一个像用户界面的Firebug的缩小版本,用户可以加载一个HTML页面,当他们将鼠标悬停在他们会突出显示。该应用程序将允许用户选择一个表格屏幕抓取....还没有到那个部分。.NET的萤火虫像UI协助

有什么建议吗?

感谢

回答

3

嗯,我没有使用Firebug的用户界面,但我做了什么你描述使用WinForms应用程序的.NET 2.0 WebBrowser控件。

基本上,我添加了WebBrowser和一个Timer控件,然后在定时器过期事件中,我使用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来解析你认为合适的。

Richard

+0

这是一个伟大的开头!非常感谢。 – 2008-10-06 01:55:22