码迷,mamicode.com
首页 > Windows程序 > 详细

c# winform 窗体间的传值

时间:2017-08-16 11:31:29      阅读:290      评论:0      收藏:0      [点我收藏+]

标签:arch   银行   show   style   res   har   util   ted   one   

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       }

 

c# winform 窗体间的传值

标签:arch   银行   show   style   res   har   util   ted   one   

原文地址:http://www.cnblogs.com/bonnie-w/p/7371974.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!