Blogger news

Blogger templates

Wednesday, February 9, 2011

Simple Clock in Windows 7 Mobile


Here i am going to make a simple clock for windows 7 mobile.

If you didn't setup your machine for Windows 7 Mobile application please click here to see steps to setup machine
To start,

1. Open Visual Studio
2. File->New Project->Silverlight for Windows Phone and select Windows Phone

Click image below to see the same,

Inside the content panel grid add a textblock as below,

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">

<TextBlock Name="txtblk"

FontFamily="Arial" FontSize="56" FontStyle="Normal" FontWeight="Bold"

HorizontalAlignment="Center" VerticalAlignment="Center" />

Grid>


Now go to MainPage.XAML.CS and paste this code,

using System;

using System.Windows.Threading;

using Microsoft.Phone.Controls;

namespace SampleClock

{

public partial class MainPage : PhoneApplicationPage

{

// Constructor

public MainPage()

{

InitializeComponent();

DispatcherTimer tmr = new DispatcherTimer();

tmr.Interval = TimeSpan.FromSeconds(1);

tmr.Tick += OnTimerTick;

tmr.Start();

}

public void OnTimerTick(object sender, EventArgs e)

{

txtClock.Text = DateTime.Now.ToLongTimeString();

}

}

}

When you run the application you will get phone emulator with clock as shown below,



No comments:

Post a Comment