Form2的构造函数: public partial class Form2 : Form { public Form1 frm1; public Form2(Form1 f1) { InitializeComponent(); frm1 = f1; } ...... 在Form2中就可以使用Form1了如果要访问Form1中的lable: 可以在Form1中添加一个访问label的方法,如下: public string getLabel() { return this.label.Text; }然后在Form2中就可以使用frm1.getLabel()来操作Form1中的lable了。
这个需要Form2在Form1后声明还可以在Program里面写一个公共的List,存放所有存在的Form的引用,直接从Form2里面访问这个List,获取引用,就可以访问了
pulic string mystr=this.lable1.text.ToString();Form2:
Form1 f1=new Form();
MessageBox.show(f1.mystr);
public partial class Form2 : Form
{
public Form1 frm1;
public Form2(Form1 f1)
{
InitializeComponent();
frm1 = f1;
}
......
在Form2中就可以使用Form1了如果要访问Form1中的lable:
可以在Form1中添加一个访问label的方法,如下:
public string getLabel()
{
return this.label.Text;
}然后在Form2中就可以使用frm1.getLabel()来操作Form1中的lable了。