允许滚动鼠标,但不显示浏览器的滚动条? [英] Allow scroll with mouse but don't show browser scrollbars?

查看:192
本文介绍了允许滚动鼠标,但不显示浏览器的滚动条?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a Form with a Web Browser, I don't want to show the scrollbars in the web browser, but I want to allow the user to scroll down the website with the mouse wheel.

我该怎么办呢?

感谢。

推荐答案

修改

在很多工作,我已经得到了解决!

After much work, I've gotten a solution!

我用VB.net,然后转换它交给C#:

I used VB.net and then converted it over to 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);
}

现在,该文本文件添加到您的资源(或地方)。

Now, add this text file to your resources (or wherever).

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)。

Now, on the line where it says scriptEl.innherHtml = My.Resources.TextFile1;, just have it put in the second file (the javascript).

在该行 window.scrollBy(0,-delta * 20),改变了20的任何号码,您觉得最重presents正常滚动。其中20位认为体面的给我。

On the line window.scrollBy(0,-delta*20), change the 20 to whatever number you feel best represents normal scrolling. 20 felt decent to me.

在C#code需要在'的DocumentComplete事件内把您的web浏览器对象。

The C# code needs to be put inside of the 'DocumentComplete' event for your WebBrowser object.

希望帮助!它的工作对我来说:)

Hope that helps! It worked for me :)

这篇关于允许滚动鼠标,但不显示浏览器的滚动条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆