我正在用C#开发一个桌面应用程序....我想每5分钟自动刷新一次表格....所以我该怎么做? [英] I Am Developing One Desktop Application In C#.... I Want To Auto Refresh The Form After Every 5 Minutes.... So How Can I Do This ?

查看:125
本文介绍了我正在用C#开发一个桌面应用程序....我想每5分钟自动刷新一次表格....所以我该怎么做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I am developing one desktop application in C#.... i want to auto refresh the form after every 5 minutes.... so how can i do this ?

推荐答案

在表单上使用计时器,将间隔设置为5分钟,然后在timer_Tick事件处理程序中,编写代码以重新加载表单内容.
Use a timer on form, set the interval to 5 mins and in timer_Tick event handler, write code to reload the form content.


通过使用Timer u可以获得此

1.拖动计时器控制
2.右键单击计时器Control的转到属性
3.启用= true
4.时间间隔= 300000
5.双击滴答声事件

每5分钟timer1_Tick(event)它将在.Cs上触发

您要刷新的内容,您应该像这样在timer1_Tick(event)上调用

private void timer1_Tick(对象发送者,EventArgs e)
{
resetControls();

}

公共无效resetControls()
{
////Reset(初始状态)形式的控件/////
Textbox1.text = string.Empty;
Lable1.text = string.Empty;
Dropdown.SelectedIndex = 0;
}
By the use of Timer u can get this

1.Drag Timer Control
2.Right click on timer Control go properties
3.Enabled =true
4. Interval=300000
5.Double click on Tick Event

Every 5 minutes timer1_Tick(event) it will fire on .Cs

what u want do refresh u should call at timer1_Tick(event) like this

private void timer1_Tick (object sender, EventArgs e)
{
resetControls();

}

public void resetControls()
{
////Reset(initial state ) Controls of Form /////
Textbox1.text=string.Empty;
Lable1.text=string.Empty;
Dropdown.SelectedIndex=0;
}


进一步解决方案1-我更喜欢在代码中使用Timers而不是控件(仅是我).我还希望不要重新加载表单,而只是重新填充

这是一个示例:
Further to Solution 1 - I prefer to use Timers in code rather than the control (that''s just me). I also prefer not to reload the form, just re-populate it

Here is an example:
public partial class Form1 : Form
    {
        Timer refreshTimer = new Timer();       // Create timer in code
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            refreshTimer.Interval = 300000;
            refreshTimer.Tick += new System.EventHandler(RefreshForm);
            refreshTimer.Enabled = true;
            refreshTimer.Start();
        }
        private void RefreshForm(object sender, EventArgs e)
        {
            // This code contains whatever you are using to refresh the data
            // Note the parameters are required to turn this function into a Tick handler
            this.textBox1.Text = "Refreshed";
        }
    }


这篇关于我正在用C#开发一个桌面应用程序....我想每5分钟自动刷新一次表格....所以我该怎么做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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