gpt4 book ai didi

c# - 在子窗体中单击按钮时如何刷新父窗体?

转载 作者:太空狗 更新时间:2023-10-30 00:34:30 27 4
gpt4 key购买 nike

然后关闭子窗体正在运行此命令:

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 或运行创建的新操作?

最佳答案

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

这样您就可以通知家长。

例子:

//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
}

关于c# - 在子窗体中单击按钮时如何刷新父窗体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7406560/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com