Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable WPF WebBrowser scrollbar

Tags:

wpf

xaml

I am trying to hide the webbrowser scrollbar, but it is still visible.

XAML:

<WebBrowser Name="wb" Width="700" Height="600" 
                        OverridesDefaultStyle="False"
                        ScrollViewer.CanContentScroll="False"
                        ScrollViewer.HorizontalScrollBarVisibility="Hidden" 
                        ScrollViewer.VerticalScrollBarVisibility="Hidden" />

Thank you.

like image 377
Alvin Avatar asked Oct 17 '12 08:10

Alvin


5 Answers

Adding scroll="no" to the html body tag worked for me while other suggestions here did not.

like image 67
TomerAgmon1 Avatar answered Nov 09 '22 06:11

TomerAgmon1


This works for me:

<WebBrowser LoadCompleted="wb_LoadCompleted"></WebBrowser>           

void wb_LoadCompleted(object sender, NavigationEventArgs e)
    {
        string script = "document.body.style.overflow ='hidden'";
        WebBrowser wb = (WebBrowser)sender;
        wb.InvokeScript("execScript", new Object[] { script, "JavaScript" });
    }

This way you don't need mshtml

like image 22
befstrat Avatar answered Nov 09 '22 06:11

befstrat


Not ideal but it works :

Add Microsoft.mshtml to your project references. Then change your xaml to this :

<WebBrowser Name="wb" Width="700" Height="600" 
            OverridesDefaultStyle="False"
            ScrollViewer.CanContentScroll="False"
            ScrollViewer.HorizontalScrollBarVisibility="Hidden" 
            ScrollViewer.VerticalScrollBarVisibility="Hidden"
            LoadCompleted="wb_LoadCompleted"></WebBrowser>

and in your code behind :

private void wb_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
    mshtml.IHTMLDocument2 dom = (mshtml.IHTMLDocument2)wb.Document;
    dom.body.style.overflow = "hidden";
}
like image 8
Sisyphe Avatar answered Nov 09 '22 05:11

Sisyphe


in your html ....

 html{overflow:hidden;}

it should solve it or you can use meta tag to specify Ie render mode

<meta http-equiv="X-UA-Compatible" content="IE=edge" /> 
like image 4
doron aviguy Avatar answered Nov 09 '22 06:11

doron aviguy


Add Microsoft.mshtml to your project references. You dont need to change any of the scroll properties in XAML as they are not the one controlling the webbrowser when mshtml is used. In the LoadCompleted function do the following:

private void webBrowserChat_LoadCompleted(object sender, NavigationEventArgs e)
{
    mshtml.IHTMLDocument2 documentText = (IHTMLDocument2)webBrowserChat.Document; 
    //this will access the document properties 
    documentText.body.parentElement.style.overflow = "hidden"; 
   // This will hide the scrollbar (Set to "auto" if you want to see when it passes the surfacelimit)
}
like image 1
Devdude Avatar answered Nov 09 '22 05:11

Devdude