Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unwanted scrollbars in WebBrowser control when in IE9 mode

Using the WinForms WebBrowser control in edit mode (as described here), I am experiencing unnecessary scrollbars when switching the control into "IE9 mode".

I'm using the meta tag

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

as described in this posting to switch into editing mode.

This is how it looks like when being in "IE9 mode":

enter image description here

In contrast, when using it without the above meta tag, it correctly looks like this:

enter image description here

Here, it looks as expected; the horizontal scrollbar is not present at all and the vertical scrollbar is not active.

I tried every DOCTYPE I can think of; the result seems to stay the same.

(In case it matters: The content that is being switched into edit mode comes from a local HTTP URL of the built-in mini webserver of my application, i.e. not from a string or from a file URL).

My question is:

Is there a way to use the WebBrowser control with IE9 in "IE9 edit mode" and still have the scrollbars only when necessary?

like image 844
Uwe Keim Avatar asked Feb 15 '12 13:02

Uwe Keim


People also ask

Why is there no scroll bar on my website?

Using your browser's magnification or zoom controls may cause scroll bars to disappear. Observe this phenomenon by opening a Web page and pressing "Ctrl-<minus symbol>" repeatedly. Your actions cause the page's content to shrink in size.


1 Answers

The scrollbars in the Web Browser control is determined by the document scroll settings and you can use the overFlow style to turn it off.

The following code works for me in preventing any scrollbars to appear:

    private void button1_Click(object sender, EventArgs e)
    {
        dynamic doc = this.Browser.Document.DomDocument;
        dynamic body = this.Browser.Document.Body;
        body.DomElement.contentEditable = true;

        doc.documentElement.style.overflow = "hidden";
    }
like image 198
Rick Strahl Avatar answered Oct 23 '22 03:10

Rick Strahl