WPF WebBrowser 字体大小更改功能
我希望能够使用按钮缩放 WebBrowser 控件的字体大小。
目前,我可以做类似的事情
IHTMLDocument2 doc = myBrowser.Document as IHTMLDocument2;
if (doc != null)
{
doc.execCommand("SelectAll", false, null);
doc.execCommand("FontSize", false, someSize);
doc.execCommand("Unselect", false, null);
}
}
,基本上选择我的网络浏览器中的所有内容,更改字体大小,然后取消选择。这样做的问题是,它将整个文档设置为相同的字体大小,并且它不是相对的,这意味着如果我有标题或带有某些段落的内容,那么在按下按钮后标题和段落将具有相同的大小。
仔细查看 IHTMLDocument2 接口 API,没有一个命令允许我选择文档的子集,这意味着我基本上无法做我想做的事情。我想知道是否还有其他地方可以访问 IHTMLDocument2 内子元素的字体大小属性。
I want to be able to scale the font size of my WebBrowser control with a button.
Currently, I can do something like
IHTMLDocument2 doc = myBrowser.Document as IHTMLDocument2;
if (doc != null)
{
doc.execCommand("SelectAll", false, null);
doc.execCommand("FontSize", false, someSize);
doc.execCommand("Unselect", false, null);
}
}
Which basically selects all the content in my WebBrowser, changes the font size, and deselects. The problem with this is that it sets the WHOLE document to the same font size, and it's not relative, which means if I have a header or something with some paragraphs, then the header and paragraph will have the same size after I press the button.
Sniffing around at the IHTMLDocument2 interface API, there isn't a command that allows me to select a subset of the document, which means I'm basically not able to do what I want to do. I'm wondering if there is anywhere else I can access the font size attribute of the child elements inside that IHTMLDocument2.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了答案:
其中
webBrowser
是您的 WebBrowser,而browserFontSize
是您想要将 WebBrowser 缩放到的双精度值(大于 0,不确定上限是多少)。仅当您的 IE 版本为 v7.0+ 时此功能才有效
I found the answer:
Where
webBrowser
is your WebBrowser andbrowserFontSize
is the double value (larger than 0, not sure what the cap is) you want to scale your WebBrowser to.This will only work if your IE is v7.0+