c# - 在 IE9 模式下 WebBrowser 控件中不需要的滚动条

标签 c# winforms internet-explorer webbrowser-control editmode

使用 WinForms WebBrowser control在编辑模式 ( as described here ) 中,将控件切换到“IE9 mode ”时遇到不必要的滚动条。

我正在使用元标记

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

this posting 中所述切换到编辑模式。

这是在“IE9 模式”下的样子:

enter image description here

相比之下,在没有上述元标记的情况下使用它时,它看起来像这样:

enter image description here

在这里,它看起来符合预期;水平滚动条根本不存在,垂直滚动条不活动。

我尝试了所有我能想到的 DOCTYPE;结果似乎保持不变。

(以防万一:切换到编辑模式的内容来 self 的应用程序内置迷你网络服务器的本地 HTTP URL,即不是来自字符串或文件 URL)。

我的问题是:

有没有办法在“IE9 编辑模式”下将 WebBrowser 控件与 IE9 一起使用,并且仅在必要时仍然有滚动条?

最佳答案

Web Browser 控件中的滚动条由文档滚动设置决定,您可以使用 overFlow 样式将其关闭。

以下代码对我有用,可以防止出现任何滚动条:

    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";
    }

关于c# - 在 IE9 模式下 WebBrowser 控件中不需要的滚动条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9294076/

相关文章:

c# - 使用VS 2005设计抽象形式

c# - 如何启动一个停止的线程

javascript - 什么会导致单击事件在 Internet Explorer 11 中停止工作?

c# - 无偏时间系统 C#

c# - 错误响应,OWIN 服务器中的启动选项

c# - AddResponseCompression 不适用于 .NET Core 3.1 Controller

c# - 为什么后台线程会阻塞GUI

javascript - CSS 缩放属性

internet-explorer - 如何让 PIE(IE 的 CSS3)工作?

c# - 在 Azure 文件存储中解压大型 zip 文件,没有 "Out of Memory"异常”