System.Windows.Controls.WebBrowser 的可滚动高度 [英] Scrollable Height of System.Windows.Controls.WebBrowser
问题描述
我正在使用 System.Windows.Controls.WebBrowser 控件,我需要获取呈现的 html 文档的高度.(不是控件的高度,是内容的高度)
I am using the System.Windows.Controls.WebBrowser control, and I need to get the height of the rendered html document. (Not the height of the control, the height of the content)
我发现的唯一高度值是 WebBrowser.Document.body.offsetheight.但是,这与控件的高度值相同.
The only height value I've found is WebBrowser.Document.body.offsetheight. However, this is the same value as the control's height.
我知道页面的高度必须存储在某个地方,因为滚动条知道该值.
I know the height of the page must be stored someplace since the scroll bar knows the value.
我在搜索中找到的所有内容都与 Windows.Forms.WebBrowser 相关.
Everything I find in my searching has been about the Windows.Forms.WebBrowser.
推荐答案
在项目中添加 COM 引用Microsoft HTML Object Library",并使用这个:
Add COM reference "Microsoft HTML Object Library" to the project, and use this:
mshtml.HTMLDocument doc = (mshtml.HTMLDocument)this.Browser1.Document;
mshtml.IHTMLElement2 elem = (mshtml.IHTMLElement2)doc.activeElement;
int height = elem.scrollHeight;
这篇关于System.Windows.Controls.WebBrowser 的可滚动高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!