如何基于子窗体中的另一个更新文本框? [英] How to update a textbox based on another in its subform?
本文介绍了如何基于子窗体中的另一个更新文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以将字段从父表单更新为子表单,但不会发生反向错误
请帮助我
在表单之间将数据从子表单传递到主表单
i can update fields from parent to child form but reverse is not happening
please help me
Passing Data Between Forms from sub form to main form
推荐答案
假定从Form1中打开了Form2.
在Form2中创建事件:
Assuming Form2 is opened from Form1.
Create an event in Form2:
public event EventHandler Changed;
protected virtual void OnChanged(EventArgs e)
{
EventHandler eh = Changed;
if (eh != null)
{
eh(this, e);
}
}
private void DoSomethingToChangeData()
{
OnChanged(null);
}
创建Form2的实例时,请在Form1中为Changed事件添加一个处理程序:
When you create the instance of Form2, add a handler in Form1 for the Changed event:
frmNew f = new frmNew();
f.Changed += new EventHandler(f_Changed);
f.Show();
事件触发时,对其进行处理并获取数据.
When the event fires, handle it and get the data.
void f_Changed(object sender, EventArgs e)
{
frmNew f = sender as frmNew;
if (f != null)
{
textBox1.Text = f.PropertyToGetTheText;
}
}
这篇关于如何基于子窗体中的另一个更新文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文