user741319
user741319

Reputation: 625

Reloading windows form without closing and reopening

I have an windows forms application written in c#. 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 :

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

What should I do about this? Thanks for helping..

Upvotes: 10

Views: 66026

Answers (5)

Steve
Steve

Reputation: 21

//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");
    }
}

Upvotes: 0

Nitin...
Nitin...

Reputation: 337

        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();
        }

Upvotes: 4

pankaj
pankaj

Reputation: 1914

Home is MDI-Form name. i have tested it.

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

Upvotes: 0

Junior CSharp
Junior CSharp

Reputation: 85

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.

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

Upvotes: 0

CodingBarfield
CodingBarfield

Reputation: 3398

Place the 'load' code in a separate function and call that function from you're own code/Load event handler.

Upvotes: 5

Related Questions