Csharp/C#教程:允许使用鼠标滚动但不显示浏览器滚动条?分享


允许使用鼠标滚动但不显示浏览器滚动条?

我有一个带有Web浏览器的表单,我不想在Web浏览器中显示滚动条,但我希望允许用户使用鼠标滚轮向下滚动网站。

我该怎么做 ?

谢谢。

编辑

经过大量工作,我已经找到了解决方案!

我使用VB.net然后将其转换为C#:

private void WebBrowser1_DocumentCompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e) { WebBrowser1.Document.Body.Style = "overflow:hidden"; HtmlElement head = WebBrowser1.Document.GetElementsByTagName("head")[0]; HtmlElement scriptEl = WebBrowser1.Document.CreateElement("script"); scriptEl.SetAttribute("language", "javascript"); scriptEl.InnerHtml = My.Resources.TextFile1; head.AppendChild(scriptEl); } 

现在,将此文本文件添加到您的资源(或任何地方)。

 function handle(delta) { window.scrollBy(0,-delta*20) } function wheel(event){ var delta = 0; if (!event) event = window.event; if (event.wheelDelta) { delta = event.wheelDelta/120; } if (delta) handle(delta); if (event.preventDefault) event.preventDefault(); event.returnValue = false; } if (window.addEventListener) window.onmousewheel = document.onmousewheel = wheel; 

现在,在它所说的scriptEl.innherHtml = My.Resources.TextFile1; ,只需输入第二个文件(javascript)。

在行window.scrollBy(0,-delta*20) ,将20更改为您认为最能代表正常滚动的数字。 20对我来说很体面。

需要将C#代码放在WebBrowser对象的“DocumentComplete”事件中。

希望有所帮助! 它对我有用:)

上述就是C#学习教程:允许使用鼠标滚动但不显示浏览器滚动条?分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/942228.html

(0)
上一篇 2021年11月13日
下一篇 2021年11月13日

精彩推荐