C# 在不关闭和重新打开的情况下重新加载windows窗体

C# 在不关闭和重新打开的情况下重新加载windows窗体,c#,winforms,C#,Winforms,我有一个用c#编写的windows窗体应用程序。我想在有人按下表单中的“清除”按钮时重新加载表单。但我无法实现调用加载事件。这些行也不起作用: this.Refresh(); this.Load +=new EventHandler(Grafik_Load); // 'Grafik' is the name of the form. 我该怎么办?感谢您的帮助。将“加载”代码放在一个单独的函数中,并从您自己的代码/加载事件处理程序中调用该函数。我发现隐藏/显示、显示部分会创建同一表单的另

我有一个用c#编写的windows窗体应用程序。我想在有人按下表单中的“清除”按钮时重新加载表单。但我无法实现调用加载事件。这些行也不起作用:

  this.Refresh();
  this.Load +=new EventHandler(Grafik_Load); // 'Grafik' is the name of the form.

我该怎么办?感谢您的帮助。

将“加载”代码放在一个单独的函数中,并从您自己的代码/加载事件处理程序中调用该函数。

我发现隐藏/显示、显示部分会创建同一表单的另一个实例,因此我最好先处理当前实例,再创建一个新实例并显示它

Grafik objFrmGrafik = new Grafik (); 
this.Dispose(); 
objFrmGrafik .Show();

Home是MDI表单名称。我已经测试过了

 home.ActiveForm.Dispose();
            home sd = new home();
            sd.Show();

实际上我已经有了一个加载函数,比如:private void Grafik_load(object sender,EventArgs e){….},但是我没有找到调用itApplication.Restart()的正确语法;可能会解决这个问题,但它会显示一个闪烁(关闭和打开表单),这正是帖子要求避免的。欢迎使用StackOverflow。只有代码的答案往往会被标记为删除,因为它们是“低质量的”。请阅读回答问题的帮助部分,然后考虑给你的答案添加一些评论。这不是OP问的确切内容,他希望在同一个屏幕上这样做。
        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();
        }
//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");
    }
}