网页浏览器控件打不开

发布于 2024-12-16 12:47:02 字数 886 浏览 3 评论 0原文

当我的事件触发以下代码时,get 会运行:

            WebBrowser browser = new WebBrowser();
        browser.Size = new Size(500, 500);
        browser.Dock = DockStyle.Fill;

        if (supportingInfo != null)
        {
            try
            {
                if (!String.IsNullOrEmpty(supportingInfo.Summary))
                {
                    browser.Navigate("about:blank");
                    if (browser.Document != null)
                    {
                        browser.Document.Write(string.Empty);
                    }
                    browser.DocumentText = "<html>" + supportingInfo.Summary + "</html>";

                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

我已调试并且该 get 的每一行都已运行,但没有使用我的动态 html 打开新的浏览器窗口。我缺少什么才能打开包含我的 html 的窗口?

感谢您的所有帮助。

when my event fires the following code get's run:

            WebBrowser browser = new WebBrowser();
        browser.Size = new Size(500, 500);
        browser.Dock = DockStyle.Fill;

        if (supportingInfo != null)
        {
            try
            {
                if (!String.IsNullOrEmpty(supportingInfo.Summary))
                {
                    browser.Navigate("about:blank");
                    if (browser.Document != null)
                    {
                        browser.Document.Write(string.Empty);
                    }
                    browser.DocumentText = "<html>" + supportingInfo.Summary + "</html>";

                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

I've debugged and every line of this get's run, but no new browser window opens with my dynamic html. What am I missing to make the window open with my html in it?

Thanks for all the help.

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

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

发布评论

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

评论(2

春风十里 2024-12-23 12:47:02

您需要将刚刚创建的 WebBrowser 控件添加到您希望其停靠的表单/面板中。例如,

  this.Controls.Add(browser);

您只是创建浏览器的实例并设置其属性。您实际上没有在视觉上添加它。

You need to add the WebBrowser control you just created to the form/panel you want it to dock on. e.g.

  this.Controls.Add(browser);

You're just creating an instance of the browser and settings it's properties. No where have you actually added it visually.

缪败 2024-12-23 12:47:02

看起来您缺少 browser.Show()

Looks like you are missing browser.Show()

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