I want to create small Digital clock in WPF, I did it in VS 2008 but not much nice looking. So I open Microsoft Expression Blend 3, but we cannot find timer Component in there.
  • Create WPF Application in Blend
  • Add DispatcherTimer using System.Windows.Threading.
  • With timer.Tick we can Give something to happen
  • timer.Interval can be use to define when to tick



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.Shapes;
using System.Windows.Threading;

namespace MyTimer
{
      
       ///
       /// Interaction logic for MainWindow.xaml
       ///
      
      
       public partial class MainWindow : Window
       {
              DispatcherTimer timer;
             
              public MainWindow()
              {
                     this.InitializeComponent();

                     timer = new DispatcherTimer();
                     timer.Interval = TimeSpan.FromSeconds(1.0);
                     timer.Start();
                     timer.Tick += new EventHandler(delegate(object s, EventArgs a)
        {
                    
                       tb.Text = "" + DateTime.Now.Hour +":"
                     + DateTime.Now.Minute +":"
                     + DateTime.Now.Second;
             
        
        });
              }
                    
       }
}
3

View comments

I am
I am
Archives
Total Pageviews
Total Pageviews
2 0 5 7 7 0 6
Categories
Categories
Loading