kogh
kogh

Reputation: 1015

Editing CSS within WinForms WebBrowser

I currently have a WinForms application with a WebBrowser control in it that I'm able to successfully edit the markup using the very useful HtmlAgilityPack. My question now is, how can I edit the stylesheet that my page is referencing?

Ideally I'd like to be able to get the complete ruleset, find the necessary IDs, and simply edit the CSS declaration like so: background-color:#ccc; <-- this is what I'm trying to modify on the fly (and have the CSS file saved and reload the page referencing said stylesheet).

It seems that there should be an easy solution to this, but I'm having trouble finding one.

EDIT: Also, I should point out that it may not always be "#ccc", the point being that I know exactly what selectors I want to modify, and in what classes they're under in the stylesheet. The exact color will be unknown after the first edit, so I can't just do a Replace on that background-color:#ccc rule.

Upvotes: 2

Views: 447

Answers (1)

Josh E
Josh E

Reputation: 7432

You can grab the src URL of the CSS files from the HTML of the document to get the full set of CSS styles. Then, after modifications, save the CSS to the filesystem.

Finally, to apply the changes, you can modify the <link src="..."** > to point to your updated stylesheet.

If you need to address the possibility of multiple stylesheets on a page, you could simply consolidate the contents of the individual sheet declarations into one string, and proceed with the above

Upvotes: 1

Related Questions