title: How to get font size of currently selected text in WebBrowser control
body: <p>Is there any way to get the font size of the currently selected text in the Microsoft WebBrowser control (MSHTML)?</p>
  
  <p>I am aware of <code>IHTMLDocument2::queryCommandState("FontSize", ...)</code>, 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.</p>
  
  <p>Is there a more flexible way to determine the font size?</p>
  
  <p><strong>EDIT:</strong> In the meantime, I found a solution to my question (with some helpful hints from Microsoft support):</p>
  
  <pre><code>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)
  {
  }
  </code></pre>