1.父窗体传值给子窗体:
父窗体:
1 Frm现金银行编码 frm = new Frm现金银行编码(1,0); 2 frm.Owner = this; 3 frm.ShowDialog();
子窗体:
1 int type, index = 0; 2 public Frm现金银行编码(int ty,int ind) 3 { 4 InitializeComponent(); 5 type = ty; 6 index = ind; 7 }
数据更新:
1 private void Renovate() 2 { 3 Frm现金银行 frm = new Frm现金银行(); 4 frm = (Frm现金银行)this.Owner; 5 frm.BindDgv(); //BindDgv是父窗体绑定dgv中的数据, 6 }
1 private void btnSearch_Click(object sender, EventArgs e) 2 3 ...数据增删改代码 4 if (res.Success) { 5 Renovate(); 6 this.Close(); 7 } 8 else 9 { 10 Utility.Error("添加失败:" + res.ErrMsg); 11 }
2.子窗体传值给父窗体
父窗体:
1 private void pb_wharehouse_Click(object sender, EventArgs e) 2 { 3 Frm仓库查询 frm = new Frm仓库查询(); 4 frm.P_Value+= frm_E_Value; 5 frm.ShowDialog(); 6 } 7 void frm_E_Value(string value) 8 { 9 txt_wharehouse.Text = value; //从子窗体传过来的值 10 }
子窗体:
1 public delegate void T_Value(String value); 2 public event T_Value E_Value; 3 private void btn_selected_Click(object sender, EventArgs e) 4 { 5 E_Value(this.txt_lx.Text); 6 this.Close(); 7 8 }
时间: 2024-10-03 16:54:42