例子:
现在有两个窗口form1和form2,现在form2中有个listbox。双击listbox的值以后,将选中的值传给form1中的textbox控件
[csharp]
form1中的textbox1的modifilers设为Public,
private void button1_Click(object sender, EventArgs e)
{
[csharp] view plaincopy在CODE上查看代码片派生到我的代码片
Form2 f2 = new Form2();
f2.ShowDialog(this);
}
:
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
Form1 f1 = (Form1)this.Owner;
f1.textBox1.Text = listBox1.SelectedItem.ToString();
}
现在有两个窗口form1和form2,现在form2中有个listbox。双击listbox的值以后,将选中的值传给form1中的textbox控件
[csharp]
form1中的textbox1的modifilers设为Public,
private void button1_Click(object sender, EventArgs e)
{
[csharp] view plaincopy在CODE上查看代码片派生到我的代码片
Form2 f2 = new Form2();
f2.ShowDialog(this);
}
:
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
Form1 f1 = (Form1)this.Owner;
f1.textBox1.Text = listBox1.SelectedItem.ToString();
}
public string s;
public Form1()
{
InitializeComponent();
f = this;
s = "aaa";
} private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.Show();
}form2中: private void Form2_Load(object sender, EventArgs e)
{
listView1.Items.Add(Form1.f.s);
}
private void Form2_Load(object sender, EventArgs e)
{
xz();
}
public void xz()
{
listView1.Items.Add(Form1.f.s);
MessageBox.Show("ddd");
}
{
Form1 f = new Form1();
f.xz();
f.Show();
}------------------------public void xz()
{
listView1.Items.Add("0");
}
}
{
listView1.Items.Add(Form1.f.s);
MessageBox.Show("ddd");
} 执行了MessageBox.Show("ddd"); 却没有执行listView1.Items.Add(Form1.f.s)是不可能的