主窗体含有控件Button,DataGridView
主窗体button按钮点击函数打开弹窗
private void add_Click(object sender, EventArgs e)
{
DictAdd form = new DictAdd();
form.cleareven();//去掉事件委托
form.ev += nationload;//添加事件委托
form.ShowDialog();
}
弹窗C#代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Learn
{
public partial class DictAdd : Form
{
public delegate void TableRefres(string bh, string name);
public event TableRefres ev;//委托方法 用于 刷新主窗体
/// <summary>
/// 去掉事件委托
/// </summary>
public void cleareven()
{
if (ev != null)
{
Delegate[] ar = ev.GetInvocationList();
if (ar.Length > 0)
{
foreach (Delegate a in ar)
{
ev -= a as TableRefres;
}
}
}
}
public DictAdd()
{
InitializeComponent();
}
//刷新主窗体函数
private void button1_Click(object sender, EventArgs e)
{
ev("", "");
}
}
}
主窗体刷新函数
public void load(string bh, string name)
弹窗定义TableRefres 然后声明ev事件
public delegate void TableRefres(string bh, string name);//保证参数一致