C# 在 webBrowser 控件中隐藏滚动条

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11678973/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 18:48:33  来源:igfitidea点击:

Hide Scrollbars in the webBrowser control

c#winforms

提问by Siegeon

I am working on an HTML display control for windows forms. I am using the webBrowser control as the base for my control and I need to hide the webBrowsers scroll bar, as it looks bad, will never be used, and makes the control look like a webPage which ruins the layout. Currently the scroll bar renders on the control looking all dejected and greyed out. Is there way to simply remove it all together?

我正在研究用于 Windows 窗体的 HTML 显示控件。我使用 webBrowser 控件作为我的控件的基础,我需要隐藏 webBrowser 滚动条,因为它看起来很糟糕,永远不会被使用,并使控件看起来像一个破坏布局的网页。目前,滚动条呈现在控件上,看起来都很沮丧和灰色。有没有办法简单地将其全部删除?

采纳答案by LarsTech

There is a property:

有一个属性:

webBrowser1.ScrollBarsEnabled = false;

Specifies whether the WebBrowser control should have scrollbars or not.

指定 WebBrowser 控件是否应具有滚动条。

They "can" appear however if the viewed web page is larger than the current control's size (not in all cases).

但是,如果查看的网页大于当前控件的大小(并非在所有情况下),它们“可以”出现。

This answer Allow scroll with mouse but don't show browser scrollbars?shows this method:

这个答案允许用鼠标滚动但不显示浏览器滚动条?显示此方法:

void webBrowser1_DocumentCompleted(object sender, 
                                   WebBrowserDocumentCompletedEventArgs e) {
  webBrowser1.Document.Body.Style = "overflow:hidden";
}