Windows应用程序中的计时器控制C# [英] Timer Control In Windows Application C#

查看:50
本文介绍了Windows应用程序中的计时器控制C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在5个刻度后使用计时器,特定表格应隐藏并导航到其他表格。我已经做到了,但它没有正常工作。请帮助我,我已经设置了1000毫秒的间隔



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

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;

       }










private void timer1_Tick(object sender, EventArgs e)
        {
            count++;
            if (count == 5)
            {
                Login frm = new Login();
                frm.Close();
                EmployeeDetails emp = new EmployeeDetails();
                emp.Show();
            }
           
        }

推荐答案

假设你正确设置了Timer,我怀疑你想要的是取代

Assuming that somewhere you are setting up the Timer correctly, I suspect that what you want is to replace
timer1.Enabled = true;



With

count = 0;
timer1.Start();

并添加一个电话

And add a call to

timer1.Stop();


我猜你试图关闭错误的实例。



检查这些行:在你的计时器滴答方法

登录frm = new登录();

frm.Close();



我相信BtnSubmit_Click方法在Login类中。如果是,你应该调用this.Hide。

不要使用新实例来关闭。
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.


这篇关于Windows应用程序中的计时器控制C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆