views:

353

answers:

1

I've got a System.Windows.Form.WebBrowser control on a form. I navigate that browser object to a url.

Once the page has finished loading, I'd like to analyse various aspects of the page that loaded.

In particular I'm interested to see the attribute 'writingMode' which is found on the IHTMLStyle3 interface.

Something like:

public void MyMethod(HtmlElement element)
    {
        IHTMLElement2 element2 = element.DomElement as IHTMLElement2;
        IHTMLStyle3 style3 = element2.currentStyle as IHTMLStyle3;

        string writingMode = style3.writingMode;
    ...

The problem is, the style3 value is null. I assume this means IHTMLElement2.currentStyle doesn't support IHTMLStyle3.

I've tried also tried casting IHTMLELement.style. But while that does cast happily as IHTMLStyle3 it doesn't seem to contain the style as it's been applied to the Html element.

thanks for your help!

+1  A: 

Looking at the documentation, I believe you need to get the IHTMLElement2.currentStyle property as the regular style property is the inline style only. This difference is indicated in the remarks for IHTMLElement2.currentStyle:

The values returned by the properties of the IHTMLStyle and IHTMLCurrentStyle interfaces differ when the style of an object is not set inline. For example, if the author of a Web page sets the color property of a paragraph to red only through a linked or embedded style sheet, and not inline, then the IHTMLCurrentStyle::color property returns the value red, and the IHTMLStyle::get_color property does not return a value. However, if the author specifies the value of the color property inline, as in the following example, both the IHTMLCurrentStyle::color and IHTMLStyle::get_color properties return the value red.

currentStyle provides a IHTMLCurrentStyle interface, which when queried for IHTMLCurrentStyle2 will give you writingMode as you require.

Jeff Yates
- silly me I was trying to cast currentStyle as an HTMLStyle3 - I should have been casting it as an HTMLCurrentStyle2!
Joachim Chapman