none
How do I get the font-size of a HtmlElement in one WebBrowswer control? RRS feed

  • Question

  • I am using the following code to get some HtmlElements and I need to know which has got the biggest text. Do you have any idea about this? 

    wb.Document.Body.GetElementsByTagName("p");

    I would like to get a solution that considers any kind of style (CSS, H1, or simple style attribute) applied to the HtmlElement. 

    I will appreciate any help.

    Regars

    Thursday, July 16, 2015 2:21 PM

Answers

  • If it helps somebody, you can use: 

    HtmlElement e =   wb.Document.Body.FirstChild;
    string sFontSize = ((mshtml.HTMLParaElement)(e.DomElement)).currentStyle.fontSize;

    Notice that you need to add a reference to Microsoft.mshtml


    • Marked as answer by Ayorus Thursday, July 16, 2015 3:58 PM
    • Edited by Ayorus Thursday, July 16, 2015 4:16 PM
    Thursday, July 16, 2015 3:58 PM

All replies

  • If it helps somebody, you can use: 

    HtmlElement e =   wb.Document.Body.FirstChild;
    string sFontSize = ((mshtml.HTMLParaElement)(e.DomElement)).currentStyle.fontSize;

    Notice that you need to add a reference to Microsoft.mshtml


    • Marked as answer by Ayorus Thursday, July 16, 2015 3:58 PM
    • Edited by Ayorus Thursday, July 16, 2015 4:16 PM
    Thursday, July 16, 2015 3:58 PM
  • Hi Ayorus,

    Glad to knowyou solved this problem and thanks for sharing the solution.

    It will be very beneficial for other community members who have the similar questions.

    Have a nice day!

    Kristin



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, July 17, 2015 9:56 AM