本文介绍了如何在不重新初始化C#的情况下将值传递给另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hell



如何将值传递给另一个而不重新初始化c#



这是什么iam试图做什么

hell

how to passing values from to another without reinitialize form c#

this is what iam trying to do

frm_employees emp_form = new frm_employees();
            emp_form.txt_empid.Text = txt_emp_code.Text;
            emp_form.Show();





此代码再次重新初始化表格我不需要这个,所以你能不能请帮助我。



提前感谢



此图片可以说清楚

[]



我是什么尝试过:





this code reinitialize the form again i don't need this,so could you please help me with this.

thanks in advance

this image can make it clear
http://i.imgur.com/cFZL66t.jpg[^]

What I have tried:

frm_employees emp_form = new frm_employees();
            emp_form.txt_empid.Text = txt_emp_code.Text;
            emp_form.Show();

推荐答案

public partial class FormChildEmployee : Form
    {
        public frm_employees ParentFormObject { get; set; }  // create a property for parent form

        public FormChildEmployee()
        {
            InitializeComponent();
        }
         
        private void btnSelect_Click(object sender, EventArgs e)
        {
            ParentFormObject.txt_empid.Text = txt_emp_code.Text; // assign the child's textbox value to the parent form Textbox without creating new instance
        }
    }
















// opening the child pop up on button click in parent form
private void btnOpenPopUpChild_Click(object sender, EventArgs e)
       {
           FormChildEmployee objChild = new FormChildEmployee();
           objChild.ParentFormObject = this; // initialise this object( parent form ) to the property created.
           objChild.Show();
       }





注意:将父表单文本框( txt_empid )设为设计视图中的公共修饰符。



这篇关于如何在不重新初始化C#的情况下将值传递给另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-17 00:29