Silverlight 计时器
生活随笔
收集整理的這篇文章主要介紹了
Silverlight 计时器
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
代碼 public partial class MainPage : UserControl
{
int i = 1;
TextBlock myTextBlock;
public MainPage()
{
InitializeComponent();
myTextBlock = new TextBlock();
myTextBlock.Loaded += this.StartTimer;
myTextBlock.Margin = new Thickness(30);
LayoutRoot.Children.Add(myTextBlock);
}
public void StartTimer(object o, RoutedEventArgs sender)
{
//創建計時器
System.Windows.Threading.DispatcherTimer myDispatcherTimer = new System.Windows.Threading.DispatcherTimer();
//創建間隔時間
myDispatcherTimer.Interval = new TimeSpan(0,0,0,1);
//創建到達間隔時間后需執行的函數
myDispatcherTimer.Tick += new EventHandler(Each_Tick);
//開啟計時器
myDispatcherTimer.Start();
}
public void Each_Tick(object o, EventArgs sender)
{
myTextBlock.Text = i++.ToString() + " 秒";
}
}
?
轉載于:https://www.cnblogs.com/hl3292/archive/2010/11/30/1891696.html
總結
以上是生活随笔為你收集整理的Silverlight 计时器的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用jquery打造一个动态的预览产品颜
- 下一篇: Java 包装类 自动装箱和拆箱