Unwanted scrollbars in a WebBrowser control in IE9 mode

Using WinForms WebBrowser control in edit mode ( as described here ), I experience unnecessary scroll bars when switching the control to IE9 mode.

I use meta tag

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

as described in this publication to go into edit mode.

Here's what it looks like when you are in IE9 mode:

enter image description here

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

enter image description here

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

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

(In case this is important: the content that switches to edit mode comes from the local HTTP URL of the built-in mini-server of my application, that is, not from a string or from the file URL).

My question is:

Is there a way to use the WebBrowser with IE9 in β€œIE9 edit mode” and still have scrollbars only when needed?

+6
source share
1 answer

The scroll bars in the web browser control are determined by the scroll options of the document, and you can use the overFlow style to disable it.

The following code works for me in preventing scrollbars from appearing:

  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"; } 
+5
source

Source: https://habr.com/ru/post/908512/


All Articles