如何从 form3 访问 form1.webbrowser?

How to access form1.webbrowser from form3?

我用 C# 制作了一个网络浏览器 Windows 表单,我将表单 3 设为历史记录,表单 3 包含列表框和一个名为 go 的按钮!

我希望 button_click 将 webbrowser1(位于 form1 中)导航到 listbox1.selecteditem.tostring()

在 form1 构造函数中:

public Form1()
{
    x = new Form3();
    x.Show();
    x.Visible = false;
    InitializeComponent();
}

并在打开表单 3 的按钮中

{
    x.Visible = true;
}

在 form 3 按钮中说开始:

{
    // namespace.form1.webbrowser1.navigate(listbox1.selecteditem.tostring()); // 
    this.Visible = false;
}

注释行中的错误,从 form 3 访问 webbrowser 的解决方案是什么!!

Form1作为参数传递给Form3构造函数:

class Form3
{
    Form1 _parent;
    public Form3(Form1 parent)
    {
        _parent = parent;
    }

    public void Method()
    {
        _parent.webbrowser1.navigate(listbox1.selecteditem.tostring());
        this.Visible = false;
    }
}

另外,制作 webbrowser1 public 或更好地在 Form1:

中制作一个 public 方法
class Form1
{  
    public void Navigate(string uri)
    {
        webbrowser1.navigate(uri);
    }
}

并从 Form3:

调用它
    public void Method()
    {
        _parent.Navigate(listbox1.selecteditem.tostring());
        this.Visible = false;
    }