表单4中的按钮在表单1中不会触发
本文关键字:表单 按钮 | 更新日期: 2023-09-27 18:17:47
目标是单击FORM4中的Button1,然后允许WebBrowser1在FORM1中导航到该站点。
我一直得到这个错误:错误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)
{
}
}
像这样更新你的函数(将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();
}
}
您的Form4
类只有一个构造函数,并且有一个参数Form1
。
根据它的外观,您希望在单击事件
中将Form1
实例传递到Form4
构造函数中。if (mForm == null)
{
mForm = new Form4(this);
mForm.FormClosed += new FormClosedEventHandler(mForm_FormClosed);
mForm.Show();
}