首页 > 代码库 > c# wpf定时器的一种用法
c# wpf定时器的一种用法
1、xaml页面<Window x:Class="EssentialWPF.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <Button Name="_button1" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="9pt"> Hello World </Button> </Grid></Window>2、后台using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;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.Windows.Threading;namespace EssentialWPF{ /// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { long _start; public MainWindow() { InitializeComponent(); DispatcherTimer timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromMilliseconds(50); _start = Environment.TickCount; timer.Tick += timer_Tick; timer.IsEnabled = true; } void timer_Tick(object sender, EventArgs e) { long elapsed = Environment.TickCount - _start; if (elapsed >= 5000) { _button1.FontSize = 18.0; ((DispatcherTimer)sender).IsEnabled = false; return; } _button1.FontSize = 9.0 + (9.0 / (5000.0 / elapsed)); } }}
c# wpf定时器的一种用法
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。