有什么方法可以获取 Microsoft WebBrowser 控件 (MSHTML) 中当前选定文本的字体大小?
我知道IHTMLDocument2::queryCommandState("FontSize", ...)
,但是对于过时的字体大小“xx-small”到“xx-large”,此方法仅返回 1 到 7 之间的值。对于像“10pt”或“14px”这样的字体大小,没有返回有用的值。
有没有更灵活的方法来确定字体大小?
编辑:与此同时,我找到了我的问题的解决方案(微软支持提供了一些有用的提示):
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)
{
}