栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C# > C#教程

WPF实现钟表效果

C#教程 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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();
    }

  }
}

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

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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/123011.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号