在frm1中: public class frm1 : System.Windows.Forms.Form { string 要传的分 = "分"; public string _要传的分 { get { return 要传的分; } } }在frm2中:frm1 frm = new frm1(); string 接受分; 接分=frm._要传的分;
Of courseYou may change the modifier of your button from private to public in source code, or change it by properties explorer.( There is a Modifiers property in properties explorer. In Design group.)Then you can use "form1.textbox1.Text=form2.textbox1.Text" (Both the modifier of the textbox1 of form1 and form2 are public)
private void button7_Click(object sender, System.EventArgs e)
{
Fr_zspzd zspzd=new Fr_zspzd(this.dataSet11,this.myToolbar1);
zspzd.Show();
}窗体Fr_zspzd:
public class Fr_zspzd : System.Windows.Forms.Form
{
DataSet ds1=null;
myBaseForm.myToolbar myToolbar1;
...........
public Fr_zspzd(DataSet ds,myBaseForm.myToolbar myToolbar) //构造函数
{
ds1=ds;
myToolbar1=myToolbar; //把传递的信息保存下来
........
}
private void Fr_zspzd_Load(object sender, System.EventArgs e)
{
//函数中就可以使用了
//传递的值是和第一个页面是同步的
}也可以用属性传:
private void button5_Click(object sender, System.EventArgs e)
{
WindowsApplication1.Form2 f2 = new Form2();
f2.MdiParent=this;
f2.Show();
}//-----------------------------------------------
public class Form2 : System.Windows.Forms.Form
{
private Form1 fm1;
public Form1 Fm1
{
get{return fm1;}
set{fm1=value;}
}
public class frm1 : System.Windows.Forms.Form
{
string 要传的分 = "分";
public string _要传的分
{
get
{
return 要传的分;
}
}
}在frm2中:frm1 frm = new frm1();
string 接受分;
接分=frm._要传的分;
{
Form2 frm2 = new Form2(this);
frm2.Show();
}
public string TEXTBOX1
{
set
{
textBox1.Text = value;
}
}
//Form2
public Form2(Form1 frm1) : this()
{
this.frm1 = frm1;
}
private void button1_Click(object sender, System.EventArgs e)
{
System.Reflection.Assembly a = System.Reflection.Assembly.GetExecutingAssembly();
System.Type t = a.GetType("MyNamespace.Form1", false);
System.Reflection.PropertyInfo pi = t.GetProperty("TEXTBOX1");
pi.SetValue(frm1, this.textBox1.Text, null);
}