如何将系统时间动态显示在form窗体的标题栏上

霜寒月冷 2008-09-24 07:04:17
如何将系统时间动态显示在form窗体的标题栏上
...全文
301 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
再见品月 2008-09-25
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 chz415767975 的回复:]
引用 3 楼 qlu0634 的回复:
加一个Time控件  在FORM1的LOAD事件中添加:
private void Form1_Load(object sender, EventArgs e)
{
timer1.Enabled = true;
timer1.Interval = 1000;
}
然后在timer1_Tick事件中添加代码:
private void timer1_Tick(object sender, EventArgs e)
{
toolStripStatusLabel1.Text = "现在是:"+System.DateTime.Now.ToString();
} …

想把时间显示在标题兰上的!!
[/Quote]
LZ開動下自己的大腦。。。人家能實現在一個lable上顯示。。讓你在標題欄上你還要問?
多動下手吧,對自己有好處
霜寒月冷 2008-09-24
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 qlu0634 的回复:]
加一个Time控件 在FORM1的LOAD事件中添加:
private void Form1_Load(object sender, EventArgs e)
{
timer1.Enabled = true;
timer1.Interval = 1000;
}
然后在timer1_Tick事件中添加代码:
private void timer1_Tick(object sender, EventArgs e)
{
toolStripStatusLabel1.Text = "现在是:"+System.DateTime.Now.ToString();
} …
[/Quote]
想把时间显示在标题兰上的!!
wartim 2008-09-24
  • 打赏
  • 举报
回复
不想用计时器timer的话:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Threading;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
Thread SetTitleThread = null;
delegate void SetTitle();

public Form1()
{
InitializeComponent();
SetTitleThread = new Thread(new ThreadStart(SetTitleSafely));
SetTitleThread.IsBackground = true;
SetTitleThread.Start();
}

void DoSetTitle()
{
this.Text = DateTime.Now.ToString("HH:mm:ss.fff");
}

void SetTitleSafely()
{
int StartTickCount = Environment.TickCount;
while (true)
{
if (this == null)
continue;
int EndTickCount = Environment.TickCount;
if (EndTickCount - StartTickCount > 1 * 1000) // 1秒
{
StartTickCount = EndTickCount;
SetTitle PSetTitle = new SetTitle(DoSetTitle);
if (this.InvokeRequired)
this.Invoke(PSetTitle, null);
else
this.Text = DateTime.Now.ToString("HH:mm:ss.fff");
}
}
}
}
}
youngqp 2008-09-24
  • 打赏
  • 举报
回复
呵呵,目前来说,这个方法是最方便的。
qlu0634 2008-09-24
  • 打赏
  • 举报
回复
加一个Time控件 在FORM1的LOAD事件中添加:
private void Form1_Load(object sender, EventArgs e)
{
timer1.Enabled = true;
timer1.Interval = 1000;
}
然后在timer1_Tick事件中添加代码:
private void timer1_Tick(object sender, EventArgs e)
{
toolStripStatusLabel1.Text = "现在是:"+System.DateTime.Now.ToString();
}
这样每隔一秒动态显示事件在状态栏中!
再见品月 2008-09-24
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 dragonzhong 的回复:]
我觉得可以用Timers类的事件,每隔一秒就有一个事件取得当前系统时间显示在标题栏
[/Quote]
目前俺的知識,也就是這樣能實現,
其他的應該也有,不知道了。
dragonzhong 2008-09-24
  • 打赏
  • 举报
回复
我觉得可以用Timers类的事件,每隔一秒就有一个事件取得当前系统时间显示在标题栏

110,567

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧