单击子窗体中的按钮时如何刷新父窗体? [英] How to refresh parent form when in child form is button clicked?

查看:26
本文介绍了单击子窗体中的按钮时如何刷新父窗体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

然后关闭子窗体正在使用此命令:

then closing child form is working this command:

private void listView1_MouseDoubleClick(object sender, EventArgs e)
{
    ListViewItem item = listView1.SelectedItems[0];
    string s = item.SubItems[6].Text;
    q = m;
    CommercialOfferEditProperties ob = new CommercialOfferEditProperties(s, q);
    ob.FormClosed += new FormClosedEventHandler(ob_FormClosed);
    ob.Show(); //show child
}

void ob_FormClosed(object sender, FormClosedEventArgs e)
{
   some action
}

但是如何在子窗体中单击按钮时运行 ob_FormClosed 操作或运行创建的新操作?

But how to run action ob_FormClosed or run created new action, when in child form is button clicked?

推荐答案

  1. 向您的子表单添加 OnClick 事件 (CommercialOfferEditProperties)
  2. 在父表单中订阅.
  3. 每次单击子窗体按钮时触发 OnClick.

这样你就可以通知家长了.

That way you will be able to notify the parent.

示例:

//Child form declaration

public class CommercialOfferEditProperties:Form
{

public event EventHandler ButtonClicked;

public void NotifyButtonClicked(EventArgs e)
{
       if(ButtonClicked != null)
       ButtonClicked(this,e);

}

...

}

父表单:

private void listView1_MouseDoubleClick(object sender, EventArgs e)
        {
            ListViewItem item = listView1.SelectedItems[0];
            string s = item.SubItems[6].Text;
            q = m;
            CommercialOfferEditProperties ob = new CommercialOfferEditProperties(s, q);
            ob.FormClosed += new FormClosedEventHandler(ob_FormClosed);
            ob.ButtonClicked += new EventHandler(ob_ButtonClicked);
            ob.Show(); //show child
        }

        void ob_FormClosed(object sender, FormClosedEventArgs e)
        {
           //process form close
        }

        void ob_ButtonClicked(object sender, EventArgs e)
        {
           //process button clicked
        }

这篇关于单击子窗体中的按钮时如何刷新父窗体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆