我一直在用c#开发项目。
它有两种形式,它们之间相互连接。
我希望在关闭第二个表单时首先执行表单刷新。
如果我使用Thread的Sleep程序会很累。我希望通过结束活动来做到这一点。我该怎么办?(就像java的重绘一样)
代码低于: 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();
}
答案 0 :(得分:5)
以第一种形式绑定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.
}
答案 1 :(得分:0)
'第二种形式的按钮将被关闭 ' form1是表单2关闭时要重新加载的表单
private void btn_close_Click(object sender,EventArgs e) form1.close()'在关闭form2之前卸载表单1 form1.show()'表格1重装 卸货(我)'关闭表格2 结束子
答案 2 :(得分:0)
这是一个工作样本。在父表单中
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 ,我从那里学到了。