[英]Reloading windows form without closing and reopening
I have an windows forms application written in c#. 我有一个用c#编写的Windows窗体应用程序。 I want to reload form when someone press the "clear" button in it. 当有人按下“清除”按钮时,我想重新加载表单。 But I couldn't achieve to call Load event.These lines didn't also work : 但我无法实现调用Load事件。这些行也不起作用:
this.Refresh();
this.Load +=new EventHandler(Grafik_Load); // 'Grafik' is the name of the form.
What should I do about this? 我该怎么办? Thanks for helping.. 谢谢你帮忙..
将'load'代码放在一个单独的函数中,并从您自己的代码/ Load事件处理程序中调用该函数。
private void callonload()
{
//code which u wrriten on load event
}
private void Form_Load(object sender, EventArgs e)
{
callonload();
}
private void btn_clear_Click(object sender, EventArgs e)
{
callonload();
}
i found that the hide/show, the show part creates another instance of the same form, so I better dispose the current one, create a new instance of it, and show it. 我发现hide / show,show部分创建了同一个表单的另一个实例,所以我最好配置当前的一个,创建它的新实例,并显示它。
Grafik objFrmGrafik = new Grafik ();
this.Dispose();
objFrmGrafik .Show();
Home is MDI-Form name. Home是MDI-Form名称。 i have tested it. 我测试过了。
home.ActiveForm.Dispose();
home sd = new home();
sd.Show();
//it is a good idea to use the 'sender' object when calling the form load method
//because doing so will let you determine if the sender was a button click or something else...
private void button2_Click(object sender, EventArgs e)
{
//you may want to reset any global variables or any other
//housekeeping before calling the form load method
Form1_Load(sender, e);
}
private void Form1_Load(object sender, EventArgs e)
{
if (sender is Button)
{
//the message box will only show if the sender is a button
MessageBox.Show("You Clicked a button");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.