简体   繁体   中英

WebBrowser Control does not open

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.

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

  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.

好像您缺少browser.Show()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM