c#怎样在lable中填入活动的时间
来源:百度知道 编辑:UC知道 时间:2024/05/16 12:49:43
就是让lable中的时间和系统的时间同步运动
相当于一个时钟
相当于一个时钟
加个TIMER控件,再加入如下代码:
void MainFormLoad(object sender, EventArgs e)
{
timer1.Enabled=true;
timer1.Interval=1000; //时间间隔为1秒
}
void Timer1Tick(object sender, EventArgs e)
{
this.label1.Text = System.DateTime.Now.ToString();
}
若是想获得服务器端的时间并同步的话,可以用ASP.NET Ajax
到http://www.asp.net/ajax/下载并安装最新的ASP.NET Ajax控件,这样你的VS的toolbox中就会多了一个ASP.NET Ajax Extensions,在页面上放置一个ScriptManager和一个Timer控件,比如加入是Timer1
在代码中加入:
protected void Page_Load(object sender, EventArgs e)
{
this.Timer1.Interval=1000;
}
protected void Timer1Tick(object sender, EventArgs e)
{
this.Label1.Text = DataTime.Now.ToString();
}
还是用javascript好,这样不用连接服务器
最好用js 来做吧
<html>
<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta http