WPF实现钟表效果

这篇文章主要为大家详细介绍了WPF实现钟表效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

和之前一样首先看一下WPF钟表效果图

是不是很炫酷,上面的那个花都是带有动画效果的图片 。

接下来就是代码了。

首先看一下整个场景的布局搭建

          

场景的搭建比较死板,没有用代码去创建整个场景,位置都是自己一个一个的慢慢的摆放的比较随意。

下面就是程序的代码了。

 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.Timers; using System.Windows.Navigation; using System.Windows.Threading; namespace QQDemo1 { ///  /// DateTime.xaml 的交互逻辑 ///  public partial class DateTimew : Window { public DateTimew() { DispatcherTimer timer = new DispatcherTimer(); //时间相当于Timer timer.Tick += new EventHandler(timer_Tick); //timer.Interval = TimeSpan.FromSeconds(0.1); timer.Start(); InitializeComponent(); this.datatime.WindowStyle = System.Windows.WindowStyle.None; //this.datatime.WindowState = System.Windows.WindowState.Normal; this.datatime.AllowsTransparency = true;//透明 this.Background = Brushes.Transparent;//背景透明5 this.datatime.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen; //this.time.Content = ; // DateTime d = new DateTime(); // this.xiaoshiImg.RenderTransformOrigin = new Point(0.85,0.85); } void timer_Tick(object sender, EventArgs e) { this.time.Content = DateTime.Now.ToString(); //Tick 事件 } private void Window_Loaded(object sender, RoutedEventArgs e) { } private void Image_ImageFailed(object sender, ExceptionRoutedEventArgs e) { } private void Button_Click(object sender, RoutedEventArgs e) { this.WindowState = System.Windows.WindowState.Minimized; } private void Button_Click_1(object sender, RoutedEventArgs e) { this.Close(); } } } 

这个动画的实现实在场景里面去实现的。下一节,会说到在代码里面如何去控制整个动画的实现!

以上就是WPF实现钟表效果的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » 其他教程