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)
{
}