HTML Render with inspect element functionality? HOW TO C#

后端 未结 1 723
栀梦
栀梦 2020-12-11 23:38

I want to do a HTML Render that shows a HTML Document, not necessary an online webpage. Then when I click over a HTML Control, it shows only the HTML where I clicked. The re

1条回答
  •  执念已碎
    2020-12-12 00:13

    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!

    0 讨论(0)
提交回复
热议问题