我一直在用c#开发项目。
它有2种形式,并且它们之间是相互连接的。
我想在第二个表单关闭时执行此操作,第一个表单刷新。
如果我使用Thread的Sleep程序会很累。我想通过闭幕活动来做到这一点。我该怎么办?(就像java的repaint一样)
代码如下: 表格1
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() '在关闭form2之前卸载form 1 form1.show() ' 表单 1 重新加载 卸载(我)'关闭表格2 结束子
这是一个工作示例。以家长形式
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,我从那里学到了。
绑定子表单是正确的方法,但还需要多做一步。 // 创建子表单的实例 var childForm = new ChildForm();`
// Bind the FormClosed event to a handler in the main form
childForm.FormClosed += ChildForm_FormClosed;`