| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1995 人关注过本帖
标题:[求助]在页面的Label1里面显示系统时钟怎么实现?
只看楼主 加入收藏
wuwen2100
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2005-4-15
收藏
 问题点数:0 回复次数:11 
[求助]在页面的Label1里面显示系统时钟怎么实现?
也就是说动太生成一个系统时钟,哪位帮帮我!?我是初学者。
搜索更多相关主题的帖子: 时钟 显示系统 页面 
2005-04-15 16:04
live41
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:67
帖 子:12442
专家分:0
注 册:2004-7-22
收藏
得分:0 
Web页面吗?用DateTime获取系统时钟,然后通过线程每秒钟刷新一次。
2005-04-16 11:39
唐伯猫
Rank: 8Rank: 8
等 级:贵宾
威 望:45
帖 子:5323
专家分:58
注 册:2005-8-9
收藏
得分:0 
好象用timer就可以实现,把它的isenabled属性改为true就可以了!

<iframe name="alimamaifrm" frameborder="0" marginheight="0" marginwidth="0" border="0" scrolling="no" width="300" height="170" src="/go/app/tbk_app/chongzhi_300_170.php?pid=mm_28854300_2441872_11377541&page=chongzhi_300_170.php&size_w=300&size_h=170&stru_phone=1&stru_game=1&stru_travel=1" ></iframe>
2005-08-09 18:09
host1982
Rank: 1
等 级:新手上路
帖 子:57
专家分:0
注 册:2005-8-7
收藏
得分:0 

using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data;

namespace clock { /// <summary> /// Summary description for Form1. /// </summary> public class Form1 : System.Windows.Forms.Form { private System.Timers.Timer Clock; private System.Windows.Forms.Label lbTime; private System.ComponentModel.IContainer components; /// <summary> /// Required designer variable. /// </summary> //private System.ComponentModel.Container components = null;

public Form1() { // // Required for Windows Form Designer support // InitializeComponent();

// // TOD Add any constructor code after InitializeComponent call // }

/// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); }

#region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.lbTime = new System.Windows.Forms.Label(); this.Clock = new System.Timers.Timer(); ((System.ComponentModel.ISupportInitialize)(this.Clock)).BeginInit(); this.SuspendLayout(); // // lbTime // this.lbTime.Font = new System.Drawing.Font("Arial", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.lbTime.Location = new System.Drawing.Point(8, 8); this.lbTime.Name = "lbTime"; this.lbTime.Size = new System.Drawing.Size(120, 48); this.lbTime.TabIndex = 0; this.lbTime.Text = "dd:dd:dd"; this.lbTime.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.lbTime.Click += new System.EventHandler(this.lbTime_Click); // // Clock // this.Clock.Enabled = true; this.Clock.Interval = 1000; this.Clock.SynchronizingObject = this.lbTime; this.Clock.Elapsed += new System.Timers.ElapsedEventHandler(this.Clock_Elapsed); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(126, 60); this.Controls.Add(this.lbTime); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D; this.MaximizeBox = false; this.Name = "Form1"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "时钟"; ((System.ComponentModel.ISupportInitialize)(this.Clock)).EndInit(); this.ResumeLayout(false);

} #endregion

/// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); }

public string GetTime() { string TimeInString=""; int hour=DateTime.Now.Hour; int min=DateTime.Now.Minute; int sec=DateTime.Now.Second;

TimeInString=(hour < 10)?"0" + hour.ToString() :hour.ToString(); TimeInString+=":" + ((min<10)?"0" + min.ToString() :min.ToString()); TimeInString+=":" + ((sec<10)?"0" + sec.ToString() :sec.ToString()); return TimeInString; }

private void Clock_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { if(sender==Clock) { lbTime.Text=GetTime(); } }

private void lbTime_Click(object sender, System.EventArgs e) { } } }


共同切磋,一起进步 电子邮件:host1982@ QQ:156018083
2005-08-10 19:12
host1982
Rank: 1
等 级:新手上路
帖 子:57
专家分:0
注 册:2005-8-7
收藏
得分:0 

public string GetTime() { string TimeInString=""; int hour=DateTime.Now.Hour; int min=DateTime.Now.Minute; int sec=DateTime.Now.Second;

TimeInString=(hour < 10)?"0" + hour.ToString() :hour.ToString(); TimeInString+=":" + ((min<10)?"0" + min.ToString() :min.ToString()); TimeInString+=":" + ((sec<10)?"0" + sec.ToString() :sec.ToString()); return TimeInString; }

private void Clock_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { if(sender==Clock) { lbTime.Text=GetTime(); } }

private void lbTime_Click(object sender, System.EventArgs e) { } } } 核心代码自己去看


共同切磋,一起进步 电子邮件:host1982@ QQ:156018083
2005-08-10 19:13
host1982
Rank: 1
等 级:新手上路
帖 子:57
专家分:0
注 册:2005-8-7
收藏
得分:0 
记住用的不是窗体里面的timer,用的是组建里面的timer

共同切磋,一起进步 电子邮件:host1982@ QQ:156018083
2005-08-10 19:15
yichen
Rank: 1
等 级:新手上路
帖 子:303
专家分:0
注 册:2005-3-9
收藏
得分:0 
也可以用窗体里面的 timer 啊!

衣带渐宽终不悔, 为伊消得人憔悴。 纸上得来终觉浅, 绝知此事要躬行。
2005-08-11 21:25
yichen
Rank: 1
等 级:新手上路
帖 子:303
专家分:0
注 册:2005-3-9
收藏
得分:0 
private void timer1_Tick(object sender, System.EventArgs e)
  {
   this.label1.Text=System.DateTime.Now.ToLongDateString().ToString()+" "+System.DateTime.Now.ToLongTimeString().ToString();
}

首先设置timer1的Enabled 为true。

衣带渐宽终不悔, 为伊消得人憔悴。 纸上得来终觉浅, 绝知此事要躬行。
2005-08-11 21:33
chenlong
Rank: 1
等 级:新手上路
帖 子:78
专家分:0
注 册:2005-3-24
收藏
得分:0 
在timer_click事件中写代码
this.lable1.text=System.DateofTime.now.ToString;



OK!

从孤独中体现自我,了解自我,读懂自我.长期接受(C#)Winform和项目,QQ88613211
2005-08-11 21:34
yichen
Rank: 1
等 级:新手上路
帖 子:303
专家分:0
注 册:2005-3-9
收藏
得分:0 
不好意思,我没有看清楚

衣带渐宽终不悔, 为伊消得人憔悴。 纸上得来终觉浅, 绝知此事要躬行。
2005-08-11 21:35
快速回复:[求助]在页面的Label1里面显示系统时钟怎么实现?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024970 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved