1个回答
展开全部
// ----------------EventUpdateDataGridView.cs
public delegate void OnUpdateDataGridView(object sender, MyEventArgs e);
public class MyEventArgs : EventArgs
{
public MyEventArgs(object para)
{
paras = para;
}
public object paras { get; private set; }
}
// ----------------子窗体
public partial class ChildForm : Form
{
public event OnUpdateDataGridView OnUpdateDataGridView;
/// <summary>
/// 子窗体里面某个函数来触发事件, 比如在按钮按下的时候调用这个方法
/// </summary>
private void func1()
{
OnUpdateDataGridView(this, new MyEventArgs(this.Text));
}
// .... other funcs ....
// ...
// ..
}
// -----------------父窗体
public partial class FatherForm : Form
{
public FatherForm()
{
InitializeComponent();
// 子窗体对象
ChildForm child = new ChildForm();
child.OnUpdateDataGridView += (s, e) =>
{
this.text = e.paras.ToString();
// do something
};
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询