Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

WebBrowser control (Forms) doesn't render background color on line numbers when styling tag.

$
0
0

I'm working on a C# utility that generates HTML and uses the System.Windows.Forms.WebBrowser control (.NET 4.5) to preview the rendered display of the generated code within the utility. When I style an <ol> tag, either by including the style in the tag or by referring to a CSS class containing the same style information, the background color is used only in the content part of the list items, and not in the line number area. This behavior is contrary to the behavior I have seen in all other browsers (including IE), where styling the background color in <ol> will cause the line numbers to pick up the specified background color as well.

Here is a small example to reproduce/demonstrate the problem. Display the following HTML in a System.Windows.Forms.WebBrowser control:

<html>
< body style="font-family:Consolas,Monospace;font-size:10pt;">
< ol style="color:Red;background-color:Black;">
   <li>First</li>
   <li>Second</li>
   <li>Third</li>
< /ol>
< /body>
< /html>

What you see in the WebBrowser control is:

WebBrowser behavior - incorrect

But put the same code in another browser, and the line numbers pick up the specified background color:

Standard browser (IE) - correct behavior

I have tried this in several browsers, including IE, and have found that only the WebBrowser control seems to ignore the background color in the line number area. Obviously, I want the WebBrowser preview in my utility to behave like other browsers, so that what the user sees in the preview is going to match what they see in an actual browser.

Added detail: The only way I have found to work around this WebBrowser behavior (behind the scenes) is to surround the ordered list with a <div> tag that is styled to force the background color. When I do that, the line numbers have the correct background color. Of course, this isn't part of the HTML the user has generated, so the WebBrowser control isn't actually previewing what the user is creating.

Is this behavior of the WebBrowser object by design, is it a known problem, is there a workaround (short of manually implementing line numbering instead of using the <ol> tag), or is there some property setting in the WebBrowser object that I'm missing which would cause it to use the background color behind the line numbers?

Thanks.



Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>