用c#做了两个窗体,想完成如下功能:在form2中的textbox里输入文字,相应的文字显示到form1的listbox里 10
namespace实验{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}private...
namespace 实验
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 frm = new Form2(this.lstfolder);
frm.ShowDialog(this);
}
}
}
namespace 实验
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
public Form2(ListBox lst)
{
InitializeComponent();
lstfolder = lst;
}
private ListBox lstfolder;
private void btncancel_Click(object sender, EventArgs e)
{
Close();
}
private void btnok_Click(object sender, EventArgs e)
{
lstfolder.Items.Add(textBox1.Text);
}
}
}
错误提示是:“实验.Form1”并不包含“lstfolder”的定义。请问如何修改?
终于找出问题的原因了,应该把
private void button1_Click(object sender, EventArgs e)
{
Form2 frm = new Form2(this.lstfolder);
frm.ShowDialog(this);
}
改成
private void button1_Click(object sender, EventArgs e)
{
Form2 frm = new Form2(this.listbox1);//因为lstfolder根本就不是form1的属性
frm.ShowDialog(this);
}
谢谢大家的支持 展开
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 frm = new Form2(this.lstfolder);
frm.ShowDialog(this);
}
}
}
namespace 实验
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
public Form2(ListBox lst)
{
InitializeComponent();
lstfolder = lst;
}
private ListBox lstfolder;
private void btncancel_Click(object sender, EventArgs e)
{
Close();
}
private void btnok_Click(object sender, EventArgs e)
{
lstfolder.Items.Add(textBox1.Text);
}
}
}
错误提示是:“实验.Form1”并不包含“lstfolder”的定义。请问如何修改?
终于找出问题的原因了,应该把
private void button1_Click(object sender, EventArgs e)
{
Form2 frm = new Form2(this.lstfolder);
frm.ShowDialog(this);
}
改成
private void button1_Click(object sender, EventArgs e)
{
Form2 frm = new Form2(this.listbox1);//因为lstfolder根本就不是form1的属性
frm.ShowDialog(this);
}
谢谢大家的支持 展开
11个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询