简体   繁体   中英

C# WebBrowser disable and hide scrollbar

I have WebBrowser control in my Form . and i allow JavaScript that call a method in the C# form :

[ComVisible(true)]
public class ScriptManager
{
            // Variable to store the form of type Form1.
        private Form1 mForm;

        // Constructor.
        public ScriptManager(Form1 form)
        {
            // Save the form so it can be referenced later.
            mForm = form;
        }

        // This method can be called from JavaScript.
        public void EnterFullScreenMode()
        {
            // Call a method on the form.
            mForm.EnterFullScreenMode();
        }

      }

And in the form i include this method :

public void EnterFullScreenMode()
{
    browser.ScrollBarsEnabled = false;
}

And i noticed that when i call this method to remove the scroll bar of the WebBrowser the page is refresh and the scroll bar still there. Any idea what is the issue? There is any other way to hide and disable scrolllbar?

Internally, browser.ScrollBarsEnabled is provisioned as DOCHOSTUIFLAG_SCROLL_NO flag via IDocHostUIHandler::GetHostInfo . The WebBrowser object has to reload the document for the new value to be picked up.

I'd suggest setting browser.ScrollBarsEnabled to false for once, after InitializeComponent() in your form, then control the scrolling with CSS: <body style="overflow: auto">...</body> will make scrollbars automatic, and style="overflow: hidden" will make them disappear.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM