如何获取 WebBrowser 控件中当前选定文本的字体大小
有没有办法获取 Microsoft WebBrowser 控件 (MSHTML) 中当前选定文本的字体大小?
我知道 IHTMLDocument2::queryCommandState("FontSize", ...)
,但对于过时的字体大小“xx-small”到“xx”,此方法仅返回 1 到 7 之间的值-大的”。对于“10pt”或“14px”等字体大小,不会返回有用的值。
有没有更灵活的方式来确定字体大小?
编辑:与此同时,我找到了问题的解决方案(带有来自 Microsoft 支持的一些有用提示):
try
{
mshtml.IHTMLTxtRange range = _dom.selection.createRange() as mshtml.IHTMLTxtRange;
if (range != null)
{
mshtml.IHTMLElement2 elem = range.parentElement() as mshtml.IHTMLElement2;
txtFontSize.Text = elem.currentStyle.fontSize.ToString();
}
}
catch (COMException ex)
{
}
Is there any way to get the font size of the currently selected text in the Microsoft WebBrowser control (MSHTML)?
I am aware of IHTMLDocument2::queryCommandState("FontSize", ...)
, but this method only returns a value between 1 and 7, for the outdated font sizes "xx-small" to "xx-large". For font sizes like "10pt" or "14px", no useful value is returned.
Is there a more flexible way to determine the font size?
EDIT: In the meantime, I found a solution to my question (with some helpful hints from Microsoft support):
try
{
mshtml.IHTMLTxtRange range = _dom.selection.createRange() as mshtml.IHTMLTxtRange;
if (range != null)
{
mshtml.IHTMLElement2 elem = range.parentElement() as mshtml.IHTMLElement2;
txtFontSize.Text = elem.currentStyle.fontSize.ToString();
}
}
catch (COMException ex)
{
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
既然您已经了解了如何获取它,那么这里有一种设置方法。
获取您可以使用的值
Since you found out how to get it, here is a way to set it up.
To get the value you can use