Question

I am trying to get the font size of selected range in a html document. I used queryCommandValue to get it. Some times it return an integer. And some times it is not. I don't know what is it.

And I also tried another way to get the fontsize by getting the parent emlement's style. But it's not always correct for there could be different font size in its children.

Was it helpful?

Solution

This method returns a value between 1 and 7, for font sizes from "small" to "large", like in GMail.

If you want to get a font size in points or pixels, use

mshtml.IHTMLTxtRange range = _dom.selection.createRange() as mshtml.IHTMLTxtRange;
if (range != null)
{
   mshtml.IHTMLElement2 elem = range.parentElement() as mshtml.IHTMLElement2;
   fontSize.Text = elem.currentStyle.fontSize.ToString()
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top