Click here to Skip to main content
15,897,291 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have to use timer after 5 tick that particular form should hide and navigate to other form. i have done that but its not working fine. please do help me and i have set the interval for 1000ms

C#
private void BtnSubmit_Click(object sender, EventArgs e)
       {
           label1.Visible = false;

           CommonClass.tagid = TxtTagid.Text.Trim();
           string sql_select = string.Format("SELECT EmployeeMaster.* FROM EmployeeMaster where TagId='{0}'", TxtTagid.Text.Trim());
           DataTable dt = new DataTable();
           dt = obj.NonTransaction(sql_select);
           string name = dt.Rows[0]["EmployeeName"].ToString();
           lblMsg.Visible = true;
           lblMsg.Text = "Thanks For Your Authentication" + " " + name;
           //MessageBox.Show("Thanks For Your Authentication" + " " + " "+ name);
           timer1.Enabled = true;

       }



C#
private void timer1_Tick(object sender, EventArgs e)
        {
            count++;
            if (count == 5)
            {
                Login frm = new Login();
                frm.Close();
                EmployeeDetails emp = new EmployeeDetails();
                emp.Show();
            }
           
        }
Posted
Updated 18-Dec-12 21:27pm
v3
Comments
[no name] 19-Dec-12 3:29am    
What are you getting as error... ??
ridoy 19-Dec-12 3:38am    
you need to tell us what is your problem?what do you want?
Sergey Alexandrovich Kryukov 19-Dec-12 4:07am    
OK, I see... Want to drive your user crazy? Better through out the idea and design something nice to the users...
—SA

Assuming that somewhere you are setting up the Timer correctly, I suspect that what you want is to replace
C#
timer1.Enabled = true;
With
C#
count = 0;
timer1.Start();
And add a call to
C#
timer1.Stop();
in your Tick event handler.
 
Share this answer
 
I guess you are trying to close the wrong instance.

check these lines: in your timer tick method
Login frm = new Login();
frm.Close();

I believe the BtnSubmit_Click method is inside the Login class. If yes you should call the this.Hide.
do not use a new instance to close.
 
Share this answer
 

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