WPF实现钟表效果

2019-12-30 19:36:01丽君

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

下面就是程序的代码了。

 


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
{
  /// <summary>
  /// DateTime.xaml 的交互逻辑
  /// </summary>
  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();
    }

  }
}

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

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持ASPKU。


注:相关教程知识阅读请移步到c#教程频道。