从Form2访问Form1问题我需要一些帮助

本文关键字:帮助 Form2 访问 Form1 问题 | 更新日期: 2023-09-27 18:03:28

嘿,伙计们,我想从form1访问form2,我使用这个代码…

messagebox . show (wb.name)这行正在工作,我在messagebox中获得浏览器名称,但是wb.Navigate("http://www.google.com");这行不能用

 Form1 frm = new Form1();
        foreach (Control item in frm.Controls)
        {
            if (item is WebBrowser)
            {
                WebBrowser wb = (WebBrowser)item;
                 MessageBox.Show(wb.name)
                 wb.Navigate("http://www.google.com"); 
                this.Close();
            }
        }

从Form2访问Form1问题我需要一些帮助

你可能想看看什么事件与WebBrowser对象。你对this.Close()的调用可能会导致你的失败。Try a Thread.Sleep(10000);在this.Close()之前查看结果。

navigation方法不等待WebBrowser导航到特定的页面,而是立即返回,并且异步地进行导航。该控件有一个名为DocumentCompleted的事件,当web浏览器真正导航到特定页面时调用该事件。

您应该为DocumentCompleted事件实现一个事件处理程序,并在这里写下您希望程序在导航到http://www.google.com

时执行的操作。