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.

有帮助吗?

解决方案

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()
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top