Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void Form_Load(object sender, EventArgs e)
{
     timer1 = new System.Windows.Forms.Timer();
     timer1.Interval = 900000;//5 minutes
     timer1.Tick += new System.EventHandler(Timer1_Tick);
}

private void Button1_Click(object sender, EventArgs e)
{         
    if (!timer1.Enabled)
        timer1.Start();
}

private void Timer1_Tick(object sender, EventArgs e)
{
    //do whatever you want 
     RefreshMyForm();
}


private void RefreshMyForm()
{
    
    this.close();

   
    Graph1 graph = new Graph1();
    graph.Show();

    

}


What I have tried:

i try this code to refresh my from to close it and open new one bout when i use this code it open many form in the background

C#
private void RefreshMyForm()
        {
            this.Hide();
            var Graph1 = new Graph1();
            Graph1.Closed += (s, args) => this.Close();
            Graph1.Show();

        }


and

C#
private void RefreshMyForm()
        {
            this.Hide();
            Graph1 sistema = new Graph1();
            sistema.ShowDialog();
            this.Close();

        }
Posted
Updated 13-Feb-19 20:21pm
v2

1 solution

The problem is that if this is your main form, then closing it will end your application. Which will close all child forms as well.

Why do you want to close forms, and which ones?

If it's your Graph to want to "refresh" then your "close and reopen" method could work:
private Graph myGraph = null;
private void RefreshMyForm()
{
    if (myGraph != null) 
    {
        myGraph.Close;
        myGraph = null;
    }
    myGraph = new Graph1();
    myGraph.FormClosing += new Graph_Closing;
    myGraph.Show();
}
private void Graph_Closing(object sender, EventArgs e)
{
    myGraph = null;
}
And just the graph will close and reopen.

But a better way is to add a Refresh method to your Graph form, and call that so that it can refresh itself.
 
Share this answer
 
Comments
el_tot93 13-Feb-19 8:16am    
it not working the are many red line
OriginalGriff 13-Feb-19 8:39am    
I'd have thought by now you would have remembered that we can't see what you actually typed, let alone what the compiler errors were ...

BTW: you are turning into quite a Help Vampire: you are going to get nowhere in this business unless you start looking at problems and trying to think them through for yourself instead of just trying to get others to fix them for you without any effort.
TheRealSteveJudge 13-Feb-19 8:41am    
It's a complete waste of time..
OriginalGriff 13-Feb-19 8:47am    
I'm starting to think that ... he doesn't read what you say, he doesn't seem to learn from anything, and he doesn't appear to have any idea what he is doing. :sigh:
TheRealSteveJudge 13-Feb-19 9:07am    
Exactly. This is what I also thought yesterday when I was trying to help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900