日期:2014-05-19  浏览次数:20702 次

如何实现FORM的值返回到调用页
比如我在把form2的值传给Form1点击button以后会显示好几个FORM页

------解决方案--------------------
在窗体1里面有一个一个Button
private void button1_Click(object sender, System.EventArgs e)
{
Class1.s = "我是谁? ";
Form2 obj = new Form2();
obj.ShowDialog();
}

在窗体2里面有一个TextBox和一个Button
private void button1_Click(object sender, System.EventArgs e)
{
this.textBox1.Text = Class1.s;
}

还有一个类
using System;

namespace WindowsApplication1
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
public class Class1
{
public Class1()
{

}
public static string s = null;
}
}

我运行的是可以的....
------解决方案--------------------
用委托的方式传递

FROM2中

public delegate void changelabel(string s);
public event changelabel change;

private void button1_Click(object sender, System.EventArgs e)
{
if(change != null)
{
change(this.textBox1.Text);
}

}

FROM 1中

private void button2_Click(object sender, System.EventArgs e)
{
frmlabel frm = new frmlabel();
frm.change += new frmlabel.changelabel(myevent);
frm.Show();

}
private void myevent(string s)
{
this.label2.Text = s;
}

------解决方案--------------------
估计楼主需要这样的代码才能满足要求,借用songcan(当爱已成往事) ( ) 信誉:100 的代码。

用委托的方式传递

Form2

public delegate void changelabel(double s);
public event changelabel change;

private void button1_Click(object sender, System.EventArgs e)
{
double R;
double a= Convert.ToDouble(this.textBox1.Text);
double b=Convert.ToDouble(this.textBox2.Text);
R=a+b;
if(change != null)
{
change(R);
}
}

Form1

public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, System.EventArgs e)
{
Form2 ff = new Form2();
ff.change += new Form2.changelabel(myevent);
ff.Show();
}
private void myevent(double s)
{
this.textBox1.Text=Convert.ToString(s);
}