1 用屬性傳值
(子窗體)
PRivate ArrayList arrlOut;
public ArrayList arrlIn//要用pulibc
{
set
{
this .arrlOut = value;//這裡不能用arrlIn而要單獨聲明一個變量
}
get
{
return this .arrlOut ;
}
}
(主窗體,由它向子窗體傳傳值)
using System.Collections;//ArrayList引用空間
private ArrayList arrlOut;
private void btnShowForm4_Click(object sender, EventArgs e)
{
Form4 form4StudentInformation = new Form4();
form4StudentInformation.arrlIn = this.arrlOut ;
form4StudentInformation.Show();
}
2用方法傳值
(主窗體)
using System.Collections;//ArrayList引用空間
private ArrayList arrlOut;
private void btnShowForm3_Click(object sender, EventArgs e)
{
Form3 formStudentInformation = new Form3();
formStudentInformation.setArray(arrlOut);
formStudentInformation.Show();
}
(子窗體)
private ArrayList arrlOut;
public void setArray(ArrayList arrayin)//要用pulibc
{
arrlOut = arrayin;
}
3構造函數傳值
(子窗體)
private ArrayList arrlOut;
public studentOneInformationForm(ArrayList arrlIn)//構造函數中加了參數
{
InitializeComponent();
arrlOut = arrlIn;
}
(主窗體)
private void showFormInformation_Click(object sender, EventArgs e)
{
studentOneInformationForm studentOne = new studentOneInformationForm(this.arrlOut);//傳參數
studentOne.Show();
}