HTML Render with inspect element functionality? HOW TO C#

不羁岁月 提交于 2019-11-28 14:05:21

I think that you must use System.Windows.Forms.WebBrowser control for loading your html document. Override for example OnLeftButton event of the Form. And then call WebBrowser.Document.GetElementFromPoint method. So this method will return object of HtmlElement type. As the result you'll get html element from which you could navigate to inner html source code or navigate by hierarchy of tags from your selected tag;)

I create some example for you:

private static String GetTagNameByClick(WebBrowser refWebBrowser, Int32 valScreenX, Int32 valScreenY)
    {
        Point refPoint = refWebBrowser.PointToClient(new Point(valScreenX, valScreenY));

        HtmlElement refHtmlElement = refWebBrowser.Document.GetElementFromPoint(refPoint);

        return refHtmlElement.TagName;
    }

Good luck!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!