如何在不重新初始化C#的情况下将值传递给另一个 [英] How to passing values from to another without reinitialize form C#
本文介绍了如何在不重新初始化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();
此代码再次重新初始化表格我不需要这个,所以你能不能请帮助我。
提前感谢
此图片可以说清楚
http://i.imgur.com/cFZL66t.jpg [ ^ ]
我是什么尝试过:
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();
推荐答案
参考这个例子
子表单
refer this example
Child Form
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
}
}
在父表格中
in Parent Form
// 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 )设为设计视图中的公共
修饰符。
您正在尝试使用子形式将数据传回给它的父?
这很简单 - 所有你需要的是一个事件(也许是一个属性)。
见这里:在两种形式之间传递信息,第2部分:儿童到父母 [ ^ ]
Your are trying to have a "child" form which passes data back to it's "parent"?
That's pretty simple - all you need is an event (and maybe a property).
See here: Transferring information between two forms, Part 2: Child to Parent[^]
这篇关于如何在不重新初始化C#的情况下将值传递给另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文