窗体传值
我有两个form, 一个form1,上面有两个button, 一个form2,上面有一个listBox,上面有一些item,我想点击button1时,form2出现,当点击button2时,form2上面的listBox中的item被清空。怎么做??
------解决方案--------------------http://topic.csdn.net/t/20041027/19/3497195.html
------解决方案--------------------Form2 test = new Form2();
private void button1_Click(object sender, EventArgs e)
{
test.Show();
}
private void button2_Click(object sender, EventArgs e)
{
((ListBox)test.Controls[ "listBox1 "]).Items.Clear();
}
------解决方案--------------------=============================给你一个参考 ,窗体之间 传值-====================
namespace ReadFile
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form3 fm = new Form3();
fm._val = this.textBox1.Text;
if (fm.ShowDialog() == DialogResult.OK)
{
this.textBox1.Text = fm._val;
}
}
}
}
namespace ReadFile
{
public partial class Form3 : Form
{
// 定义一个属性
public string _val;
public string val
{
get
{
return _val;
}
set
{
_val = value;
}
}
public Form3()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
_val = this.textBox1.Text;
this.DialogResult = DialogResult.OK;
this.Hide();
}
private void Form3_Load(object sender, EventArgs e)
{
this.textBox1.Text = _val;
}
}
}