在form2中搞个委托事件
public partial class Form2 : Form
{
public event EventHandler ButtonClick;
public Form2()
{
InitializeComponent();
button1.Click += new EventHandler(button1_Click);
} void button1_Click(object sender, EventArgs e)
{
OnButtonClick();
}
private void OnButtonClick() {
if (ButtonClick != null) {
ButtonClick(this, EventArgs.Empty);
}
}
}在form1中使用
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Form2 f2 = new Form2();
f2.ButtonClick += new EventHandler(f2_ButtonClick);
} void f2_ButtonClick(object sender, EventArgs e)
{
this.dataGridView1.Refresh();
}
}
public partial class Form2 : Form
{
public event EventHandler ButtonClick;
public Form2()
{
InitializeComponent();
button1.Click += new EventHandler(button1_Click);
} void button1_Click(object sender, EventArgs e)
{
OnButtonClick();
}
private void OnButtonClick() {
if (ButtonClick != null) {
ButtonClick(this, EventArgs.Empty);
}
}
}在form1中使用
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Form2 f2 = new Form2();
f2.ButtonClick += new EventHandler(f2_ButtonClick);
} void f2_ButtonClick(object sender, EventArgs e)
{
this.dataGridView1.Refresh();
}
}
解决方案 »
- 生成PPT时中文字体无效,如何解决?
- Active Directory 如何用命令打开用户对话框
- c#读写流时使用using与不使用using 有什么区别?
- 我想在DataGridView 中更新数据,再把这些数据更新到数据库中。
- windows服务内部私有方法单元测试疑问
- 怎样不允许用户在 comboBox里输入东西?
- C#的水晶报表怎样添加(详细过程)怎么样去调用.
- 学习DNN,大家指点一下
- 为什么我的consoleapplication和winform编程可以连上SQL Server2000但是web编程时却登陆失败呢
- 一定给分提/关于返回网页的时后修改相对路径成绝对路径的方法!
- 探讨一个关于多线程的问题--很多字打的很辛苦请大家帮忙--谢谢
- C#中添加目录的问题
http://community.csdn.net/Expert/topic/5486/5486385.xml?temp=.1802484
http://blog.csdn.net/yumanqing/archive/2006/10/13/1333110.aspx