WebBrowser 控件不会显示来自对象源的内容

发布于 2024-12-04 03:23:33 字数 1389 浏览 2 评论 0原文

我得到一些从外部源返回的 HTML 并设置为一个简单的字符串。但是,当我设置控件的 DocumentText 参数时,没有任何变化。这似乎是一个常见问题,我尝试了以前帖子的结果但无济于事。

另外 .show() 方法似乎没有弹出窗口?在下面的代码中,它创建一个新窗口,设置一些参数并尝试打开浏览器。

private void createWindow(String text)
    {
        if (text == null) throw new ArgumentNullException("Nothing has been returned, possible MBean Failure");
        Window a = new Window();
        a.Title = "Output";
        RichTextBox rtb = new RichTextBox();
        rtb.FontSize = 12;
        rtb.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#639FBE"));
        rtb.IsReadOnly = true;
        rtb.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
        rtb.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
        rtb.Margin = new Thickness(15);
        Grid myGrid = new Grid();
        a.Content = myGrid;
        myGrid.Children.Add(rtb);
        rtb.AppendText(text);   
        a.Height = myGrid.Height;
        a.Width = myGrid.Width;

        if (text == null) throw new ArgumentNullException("Nothing has been returned,    possible Failure");
        browser.Navigate("abount:blank");
        HtmlDocument doc = browser.Document;
        browser.Document.OpenNew(true);
        doc.Write("<HTML>" + text + "</HTML>");
        browser.DocumentText = doc.ToString();


        browser.Show();



      //  a.ShowDialog();


    }

i get some HTML returned from an external source and set to a simple string. However when i set the DocumentText param of the control nothing gets changed. This seems to be a common issue, and ive tried the results from previous posts to no avail.

Also the .show() method doesnt seem to pop the window up? In the code below it creates a new window, sets some params and tried to open the browser.

private void createWindow(String text)
    {
        if (text == null) throw new ArgumentNullException("Nothing has been returned, possible MBean Failure");
        Window a = new Window();
        a.Title = "Output";
        RichTextBox rtb = new RichTextBox();
        rtb.FontSize = 12;
        rtb.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#639FBE"));
        rtb.IsReadOnly = true;
        rtb.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
        rtb.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
        rtb.Margin = new Thickness(15);
        Grid myGrid = new Grid();
        a.Content = myGrid;
        myGrid.Children.Add(rtb);
        rtb.AppendText(text);   
        a.Height = myGrid.Height;
        a.Width = myGrid.Width;

        if (text == null) throw new ArgumentNullException("Nothing has been returned,    possible Failure");
        browser.Navigate("abount:blank");
        HtmlDocument doc = browser.Document;
        browser.Document.OpenNew(true);
        doc.Write("<HTML>" + text + "</HTML>");
        browser.DocumentText = doc.ToString();


        browser.Show();



      //  a.ShowDialog();


    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

甩你一脸翔 2024-12-11 03:23:33
  1. 您的 HTML 看起来格式不正确。 标记不是可选的
  2. WebBrowser 是一个需要添加到表单中的控件——它本身并不是一个表单。
  1. Your HTML looks malformed. <body> tags aren't optional
  2. A WebBrowser is a control that needs to be added to a form -- it is not itself a form.
执笔绘流年 2024-12-11 03:23:33

尝试在导航事件

希望这会有所帮助

Try to do document writing in Navigated event

Hope this helps

早茶月光 2024-12-11 03:23:33

您是否尝试过 NavigateToString ?这似乎比对文档进行任何操作要容易得多。

(如果您尝试过失败的事情,您应该顺便提及它们是什么以及为什么它们不起作用)

Have you tried NavigateToString? That seems to be far easier than doing anything with the document.

(If you have tried things that failed you should mention what they were and why they did not work by the way)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文