如何使用c#在标题栏中运行日期和时间 [英] how to run the date and time in the title bar using c#
本文介绍了如何使用c#在标题栏中运行日期和时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用c#和计时器控件在标题栏中运行日期和时间
how to run the date and time in the title bar using c# and timer control
推荐答案
输入代码:
Put the code:
Text = DateTime.Now.ToString("F");
在您的Timer Tick事件处理程序中。但是......从UI的角度来看,它有点过时了......
In your Timer Tick event handler. But...it's a bit naff and passe from a UI point of view...
您可以使用此代码获取DateTime,
You can get the DateTime using this code,
DateTime dateTime = DateTime.Now.ToString("MMMM, dd, yyyy hh:mm");
之后,您可以使用Timer类来执行此命令根据您的实例要求(延时)。
After that, you can use the Timer class, to execute this command as per your instance requirements (time delay).
// Create the instance, 1 second
Timer timer = new Timer(1000);
timer.Elapsed += OnTimerElapsed;
// Enable it
timer.Enabled = true;
// the functionc call, executes each time timer time elapses
private static void OnTimerElapsed(Object source, ElapsedEventArgs e)
{
// Update the TitleBar of Application here using the dateTime variable
}
正如OriginalGriff所说,这不是一个好的用户界面,也不符合Windows用户界面的标准。您应该添加 TextBlock
来显示当前(或任何其他)日期时间值。
As OriginalGriff has said, this is not a good UI and not according to the standards of the Windows UI. You should add a TextBlock
to show the current (or any other) date time value.
这篇关于如何使用c#在标题栏中运行日期和时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文