a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁 > 編程 > C# > 正文

WPF實現鐘表效果

2019-10-29 21:02:41
字體:
來源:轉載
供稿:網友

和之前一樣首先看一下WPF鐘表效果圖

WPF,鐘表

是不是很炫酷,上面的那個花都是帶有動畫效果的圖片 。

接下來就是代碼了。

首先看一下整個場景的布局搭建

<Window x:Class="QQDemo1.DateTimew"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  <Window.Resources>    <Storyboard x:Key="zhuanRote">      <DoubleAnimation RepeatBehavior="Forever" From="0" To="360" Duration="1:0:0" Storyboard.TargetName="fenImg" Storyboard.TargetProperty="RenderTransform.Angle"></DoubleAnimation>      <DoubleAnimation RepeatBehavior="Forever" From="0" To="360" Duration="0:1:0" Storyboard.TargetName="xiaoshiImg" Storyboard.TargetProperty="RenderTransform.Angle"></DoubleAnimation>      <DoubleAnimation RepeatBehavior="Forever" From="0" To="360" Duration="0:0:5" Storyboard.TargetName="zhImg" Storyboard.TargetProperty="RenderTransform.Angle"></DoubleAnimation>      <DoubleAnimationUsingKeyFrames Storyboard.TargetName="huaImg" RepeatBehavior="Forever" Storyboard.TargetProperty="RenderTransform.Angle">        <EasingDoubleKeyFrame Value="10" KeyTime="0:0:2"></EasingDoubleKeyFrame>        <EasingDoubleKeyFrame Value="30" KeyTime="0:0:4"></EasingDoubleKeyFrame>        <EasingDoubleKeyFrame Value="0" KeyTime="0:0:6"></EasingDoubleKeyFrame>        <EasingDoubleKeyFrame Value="-10" KeyTime="0:0:8"></EasingDoubleKeyFrame>        <EasingDoubleKeyFrame Value="-30" KeyTime="0:0:10"></EasingDoubleKeyFrame>      </DoubleAnimationUsingKeyFrames>    </Storyboard>  </Window.Resources>  <Window.Triggers>    <EventTrigger RoutedEvent="Loaded">      <BeginStoryboard Storyboard="{StaticResource zhuanRote}"></BeginStoryboard>    </EventTrigger>  </Window.Triggers>  <Canvas>    <Button Width="40" Height="20" Margin="560,113" Panel.ZIndex="1" Background="#72532E" Foreground="White" Content="Min" FontWeight="SemiBold" Click="Button_Click"></Button>    <Button Width="40" Height="20" Margin="610,113" Panel.ZIndex="1" Background="#72532E" Foreground="White" Content="Tchu" FontWeight="SemiBold" Click="Button_Click_1"></Button>    <Border Width="529" Height="330" Margin="145,138" Background="#FAC178"></Border>    <Label Width="236" Height="40" Margin="480,150" Name="time" FontSize="24" Canvas.Left="-66"></Label>    <Image Width="120" Height="140" RenderTransformOrigin="0.5,0.5" Name="huaImg" Margin="510,200" Source="/QQDemo1;component/TimeImage/2224.png">      <Image.RenderTransform>        <RotateTransform></RotateTransform>      </Image.RenderTransform>    </Image>    <Image Width="90" Name="fenImg" Height="40" RenderTransformOrigin="0,0.8" Margin="251,306" Source="/QQDemo1;component/TimeImage/wwww.png">      <Image.RenderTransform>        <RotateTransform></RotateTransform>      </Image.RenderTransform>    </Image>    <Image Name="xiaoshiImg" Width="48" Height="134" Margin="300,242" RenderTransformOrigin="0.5,0.8" Source="/QQDemo1;component/TimeImage/www.png" Canvas.Top="-26">      <Image.RenderTransform>        <RotateTransform></RotateTransform>      </Image.RenderTransform>    </Image>    <Image Width="867" Height="700" Source="/QQDemo1;component/TimeImage/3.png"></Image>    <Image Width="30" Height="30" Margin="300,160" Source="TimeImage/11.png"></Image>    <Image Width="30" Height="30" Margin="314,160" Source="TimeImage/12.png"></Image>    <Image Name="zhImg" RenderTransformOrigin="0.5,0.5" Width="376" Margin="0,0" Height="356" Source="TimeImage/22230.png" Canvas.Left="-59" Canvas.Top="-44">      <Image.RenderTransform>        <RotateTransform></RotateTransform>      </Image.RenderTransform>    </Image>    <Image Width="30" Height="30" Margin="310,430" Source="TimeImage/16.png"></Image>    <Image Width="30" Height="30" Margin="430,305" Source="TimeImage/13.png"></Image>    <Image Width="30" Height="30" Margin="180,305" Source="TimeImage/19.png"></Image>    <Image Width="30" Height="30" Margin="390,200" Source="TimeImage/11.png" Canvas.Left="-10" Canvas.Top="-12"></Image>    <Image Width="30" Height="30" Margin="420,255" Source="TimeImage/12.png" Canvas.Left="-6" Canvas.Top="-14" ImageFailed="Image_ImageFailed"></Image>    <Image Width="30" Height="30" Margin="380,190" Source="TimeImage/14.png" Canvas.Left="34" Canvas.Top="174"></Image>    <Image Width="30" Height="30" Margin="390,190" Source="TimeImage/15.png" Canvas.Left="-10" Canvas.Top="216"></Image>    <Image Width="30" Height="30" Margin="390,190" Source="TimeImage/17.png" Canvas.Left="-148" Canvas.Top="216"></Image>    <Image Width="30" Height="30" Margin="400,190" Source="TimeImage/18.png" Canvas.Left="-193" Canvas.Top="174"></Image>    <Image Width="30" Height="30" Margin="400,200" Source="TimeImage/10.png" Canvas.Left="-193" Canvas.Top="41"></Image>    <Image Width="30" Height="30" Margin="400,200" Source="TimeImage/11.png" Canvas.Left="-208" Canvas.Top="41"></Image>    <Image Width="30" Height="30" Margin="370,200" Source="TimeImage/11.png" Canvas.Left="-148" Canvas.Top="-12"></Image>    <Image Width="30" Height="30" Margin="320,160" Source="TimeImage/11.png" Canvas.Left="-84" Canvas.Top="28"></Image>  </Canvas></Window>

場景的搭建比較死板,沒有用代碼去創建整個場景,位置都是自己一個一個的慢慢的擺放的比較隨意。

下面就是程序的代碼了。

 

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

這個動畫的實現實在場景里面去實現的。下一節,會說到在代碼里面如何去控制整個動畫的實現!

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到c#教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 自拍偷拍欧美日韩 | 日韩欧美黄色 | 99精品全国免费观看视频软件 | 亚洲一区二区在线播放 | 亚洲精品久久久日韩美女极品合集下载 | 久久久久久久久久久久国产精品 | 蜜桃视频网站在线观看 | 日韩综合 | 日日搞夜夜操 | 呦一呦二在线精品视频 | 在线小视频 | 看片一区| 毛片a级片 | 日韩成人在线播放 | 久久久久国产一区二区三区四区 | 欧美韩国日本一区 | 成人在线播放网站 | 激情一区二区三区 | 午夜天堂精品久久久久 | 成人免费一区二区三区视频网站 | 激情久久久| 欧美国产视频 | 欧美一级视频 | 日韩精品一区二区三区中文在线 | 深夜av在线| 欧美电影一区 | 日夜夜精品 | 欧美视频h | 日韩欧美精品区 | 欧美久久视频 | 亚洲免费在线观看 | 日日摸日日爽 | 色资源在线 | 国产精品一区二区日韩新区 | 一区二区三区高清 | 日韩精品视频国产 | 99久久精品一区二区 | 国产高清无密码一区二区三区 | 国产精品自产拍在线观看 | 久久免费在线观看 | 成人免费的视频 |