Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 隐藏webBrowser滚动条wpf_C#_Wpf_Browser_Scrollbar - Fatal编程技术网

C# 隐藏webBrowser滚动条wpf

C# 隐藏webBrowser滚动条wpf,c#,wpf,browser,scrollbar,C#,Wpf,Browser,Scrollbar,我有一个webbrowser,正在加载一个.html文件。问题是,尽管我已经将ScrollViewer.VerticalScrollBarVisibility设置为“隐藏”,但滚动条仍然可见 我也尝试过这种方法,但它不起作用 <WebBrowser x:Name="personalizedWebBrowser" HorizontalAlignment="Left" VerticalAlignment="Top" ScrollViewer.CanConte

我有一个webbrowser,正在加载一个.html文件。问题是,尽管我已经将ScrollViewer.VerticalScrollBarVisibility设置为“隐藏”,但滚动条仍然可见

我也尝试过这种方法,但它不起作用

<WebBrowser x:Name="personalizedWebBrowser" HorizontalAlignment="Left"  VerticalAlignment="Top" 
                ScrollViewer.CanContentScroll="False"
                ScrollViewer.HorizontalScrollBarVisibility="Hidden" 
                ScrollViewer.VerticalScrollBarVisibility="Hidden"
                LoadCompleted="wb_LoadCompleted"/>


private void wb_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
     mshtml.IHTMLDocument2 dom = (mshtml.IHTMLDocument2)personalizedWebBrowser.Document;
     dom.body.style.overflow = "hidden";
}

私有void wb_加载已完成(对象发送方,System.Windows.Navigation.NavigationEventArgs e)
{
mshtml.ihtmldocument2dom=(mshtml.IHTMLDocument2)personalizedWebBrowser.Document;
dom.body.style.overflow=“隐藏”;
}

你能提出其他建议吗

将Microsoft.mshtml添加到项目引用中。您不需要更改xaml中的任何滚动属性,因为在使用mshtml时,它们不是控制WebBrowser的属性。在LoadCompleted功能中,您将对webbrowser的实际文档进行如下更改:

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

我通过在wpf项目中使用windows窗体WebBrowser控件解决了此问题:

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        string curDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\help";

        System.Windows.Forms.Integration.WindowsFormsHost host =
            new System.Windows.Forms.Integration.WindowsFormsHost();
        System.Windows.Forms.WebBrowser webBrowser1 = new System.Windows.Forms.WebBrowser();
        host.Child = webBrowser1;

        webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted;

        string sFileName = "file:///{0}/index.html";

        webBrowser1.Url = new Uri(String.Format(sFileName, curDir));
        webBrowser1.ScrollBarsEnabled = false;
        this.grid1.Children.Add(host);
    }

    private void webBrowser1_DocumentCompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e)
    {
        System.Windows.Forms.WebBrowser webBrowser1 = sender as System.Windows.Forms.WebBrowser;
        if(webBrowser1==null)return;
        webBrowser1.Document.Body.Style = "overflow:hidden";
    }
grid1用作webBrowser1的容器

我们还需要在项目中添加以下程序集引用:
WindowsFormsIntegration,System.Windows.Forms

对于使用VS2019的vb.net,修改DevDude的解决方案如下:

Private Sub webObjectLoaded(ByVal sender as WebBrowser, Byval as NavigationEventArgs)
  Dim dom as MSHTML.IHTMLDocument2 = sender.Document
  dom.body.style.overflow = "hidden"
End Sub
我在堆栈面板中显示了多个浏览器,因此调用代码如下所示:

Dim wb = New WebBrowser()
wb.NavigateToString(txt)
AddHandler wb.LoadCompleted, AddressOf webObjectLoaded

我从COM中添加了对“Microsoft HTML对象库”的引用,该引用在引用列表中似乎显示为Interop.MSHTML。

显然,此解决方案不起作用:。你解决这个问题了吗?