传参的方法,主要利用ArrayList 类型参数为引用传递的特性.
主窗体:
public partial class FrmMain : Form
{
private ArrayList arySf;//传递数据的变量
public FrmMain()
{
InitializeComponent();
this.arySf = new ArrayList();
this.arySf.Add("");
this.arySf.Add("");
}
...
private void btnAdd_Click(object sender, EventArgs e)
{//在主窗口中调用子窗口,传参
FrmStaff aFrmSf = new FrmStaff(arySf);
aFrmSf.ShowDialog();
if (arySf[0].ToString() != "" && arySf[1].ToString() != "")
{
FilDgvSf();
SfRefresh();
}
}
//子窗体
public partial class FrmStaff : Form
{
/// <summary>
/// 接收传过来的参数
/// </summary>
public ArrayList arySfOp;
public FrmStaff(ArrayList arySf)
{
arySfOp = arySf; //接收
InitializeComponent();
...
}
}
private void btnOK_Click(object sender, EventArgs e)
{
arySfOp[0] = mtxtSfID.Text.Trim();
arySfOp[1] = txtSfName.Text.Trim();
...
}
}
引用http://hi.baidu.com/zml2008/blog/item/132c75b33253efa4d9335a9c.html