3

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.

hawbsl
  • 15,313
  • 25
  • 73
  • 114
Vichal
  • 55
  • 6

1 Answers1

3

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()
}
Flot2011
  • 4,601
  • 3
  • 44
  • 61
  • Setting the selection being key to getting a predictable font size. – Hans Passant Mar 22 '12 at 13:29
  • I have tried this way. But it is not correct. I set each

    with font size 16pt and body font size 10pt. Then I selected multiple lines. It just got the body's font size 10pt.

    – Vichal Mar 23 '12 at 01:24