当另一个窗体关闭时,如何刷新一个窗体?
本文关键字:窗体 刷新 一个 何刷新 另一个 | 更新日期: 2023-09-27 18:11:32
我一直在用c#开发项目。
它有两种形式,它们彼此相连。
我想当第二个表单关闭时,第一个表单刷新。
如果我使用线程的睡眠程序会很累。我想在闭幕活动中这样做。(像java的repaint)
代码如下: Form1
public static Form1 form;
public Form1()
{
InitializeComponent();
form = this;
}
private void button11_Click(object sender, EventArgs e)
{
Form2 yeniform = new Form2();
yeniform.Show();
}
Form2(关闭按钮)
private void button1_Click(object sender, EventArgs e)
{
Form1.form.Invalidate();
Form1.form.Refresh();
this.Close();
}
在您的第一个表单中绑定Form_Closing
事件
//Form1
private void button11_Click(object sender, EventArgs e)
{
Form2 yeniform = new Form2();
yeniform.FormClosing += new FormClosingEventHandler(this.Form2_FormClosing);
yeniform.Show();
}
private void Form2_FormClosing(object sender, FormClosingEventArgs e)
{
//Do your stuff here.
}
'按钮' form1是表单2关闭时要重新加载的表单
private void btn_close_Click(对象发送者,EventArgs e)form1.close ()在关闭表单2之前卸载表单1form1.show ()form 1重新加载卸载(我)"关闭form2终止子
这是一个工作示例。在父窗体
private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
VendorsAddForm f = new VendorsAddForm();
f.StartPosition = FormStartPosition.CenterScreen;
f.FormClosed += new FormClosedEventHandler(child_FormClosed);
f.Show();
}
void child_FormClosed(object sender, FormClosedEventArgs e)
{
this.Refresh();
var query = dbContext.AccountObjects.Where(p => p.IsVendor == true).ToList();
accountObjectsBindingSource.DataSource = new BindingList<AccountObject>(query);
}
注:子窗体为VendorsAddForm
感谢https://www.daniweb.com/posts/jump/1302760,我从那里学到了很多