0

目标是单击 FORM4 中的 Button1,然后允许 FORM1 中的 WebBrowser1 导航到该站点。

我不断收到此错误:错误 1 ​​'NO1.Form4' 不包含采用 0 个参数的构造函数

表格 1

    Form4 mForm;
    private void button92_Click(object sender, EventArgs e)
    {

          if (mForm == null) 
          {
          mForm = new Form4();
          mForm.FormClosed += new FormClosedEventHandler(mForm_FormClosed);
          mForm.Show();
             }
        else 
          {
         if (mForm.WindowState == FormWindowState.Minimized)
           mForm.WindowState = FormWindowState.Normal;
          mForm.Focus();
          }
}

void mForm_FormClosed(object sender, FormClosedEventArgs e)
{
  mForm = null;
}

表格 4

        public partial class Form4 : Form

        {

   private Form1 m_parent;
    public Form4(Form1 frm1)
    {

        InitializeComponent();
        m_parent = frm1;

    }



    private void button1_Click(object sender, EventArgs e)
    {
        m_parent.webBrowser1.Navigate("google.com");
    }

    private void Form4_Load(object sender, EventArgs e)
    {


    }
}
4

2 回答 2

0

更新你的函数是这样的(添加this到构造函数):

private void button92_Click(object sender, EventArgs e)
{
     if (mForm == null) 
     {
         mForm = new Form4(this);
         mForm.FormClosed += new FormClosedEventHandler(mForm_FormClosed);
         mForm.Show();
     }
     else 
     {
         if (mForm.WindowState == FormWindowState.Minimized)
             mForm.WindowState = FormWindowState.Normal;
          mForm.Focus();
     }
}
于 2013-06-09T00:21:37.323 回答
0

你的Form4类只有一个构造函数,它的参数为Form1.

从外观上看,您希望在单击事件中将Form1实例传递给构造函数Form4

if (mForm == null)
{
    mForm = new Form4(this);
    mForm.FormClosed += new FormClosedEventHandler(mForm_FormClosed);
    mForm.Show();
}
于 2013-06-09T00:21:48.147 回答