Download Source Code : TimerFunction
Screen Shot :
C# Code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Timers;
using System.Windows.Forms;
using System.Windows.Threading;
namespace timeFunction
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
DispatcherTimer timer;
public MainWindow()
{
InitializeComponent();
timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(1.0);
timer.Start();
timer.Tick += new EventHandler(delegate(object s, EventArgs a)
{
label1.Content = ((DateTime.Now.Hour > 12) ? DateTime.Now.Hour % 12 : DateTime.Now.Hour) + ":"
+ DateTime.Now.Minute + ":"
+ DateTime.Now.Second
+ ((DateTime.Now.Hour > 12) ? " pm" : " am");
});
}
}
}
No comments:
Post a Comment