none
webbrowser RRS feed

  • Question

  • Hi,

    i am using webbrowser control in wpf. How would i remove a scrollbar for webbrowser control.

    Tuesday, December 3, 2013 12:19 PM

Answers

  • Hi Subbu,

    You need to remove the scrollbar after the web browser is loaded by set the overflow to hidden in the document's body style

    <WebBrowser x:Name="webBrowser" LoadCompleted="wb_LoadCompleted"/>
    public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
                webBrowser.Navigate("http://www.google.com");
            }
    
    
            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" });
            }
    }

    You can see the scrollbar disabled in the output


    srithar


    Wednesday, December 4, 2013 6:26 AM
  • Hi,

    For your question, the problem here is the WPF WebBrowser control is a wrapper around the Internet Explorer WebBrowser control.  The scrollbars it displays are owned by IE.  The WPF dependency properties aren't connected to IE.

    So we can only set overflow: hidden in web page css:

    <style type="text/css">
    body {
        overflow:hidden;
    }
    </style>

    In codebehind:

    void wb_LoadCompleted(object sender, NavigationEventArgs e)
    {
                string script = "document.body.style.overflow ='hidden'";
                wb.InvokeScript("execScript", new Object[] { script, "JavaScript" });
    }
    
    private void WebBrowser_Loaded(object sender, RoutedEventArgs e)
    {
                string URLExample = "http://www.microsoft.com";
                wb.Navigate(new Uri(URLExample));
    }

    Xaml:

    <WebBrowser Name="wb"
                        Loaded="WebBrowser_Loaded" LoadCompleted="wb_LoadCompleted" />


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, December 4, 2013 6:37 AM
    Moderator

All replies

  • Hi Subbu,

    You need to remove the scrollbar after the web browser is loaded by set the overflow to hidden in the document's body style

    <WebBrowser x:Name="webBrowser" LoadCompleted="wb_LoadCompleted"/>
    public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
                webBrowser.Navigate("http://www.google.com");
            }
    
    
            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" });
            }
    }

    You can see the scrollbar disabled in the output


    srithar


    Wednesday, December 4, 2013 6:26 AM
  • Hi,

    For your question, the problem here is the WPF WebBrowser control is a wrapper around the Internet Explorer WebBrowser control.  The scrollbars it displays are owned by IE.  The WPF dependency properties aren't connected to IE.

    So we can only set overflow: hidden in web page css:

    <style type="text/css">
    body {
        overflow:hidden;
    }
    </style>

    In codebehind:

    void wb_LoadCompleted(object sender, NavigationEventArgs e)
    {
                string script = "document.body.style.overflow ='hidden'";
                wb.InvokeScript("execScript", new Object[] { script, "JavaScript" });
    }
    
    private void WebBrowser_Loaded(object sender, RoutedEventArgs e)
    {
                string URLExample = "http://www.microsoft.com";
                wb.Navigate(new Uri(URLExample));
    }

    Xaml:

    <WebBrowser Name="wb"
                        Loaded="WebBrowser_Loaded" LoadCompleted="wb_LoadCompleted" />


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, December 4, 2013 6:37 AM
    Moderator