Study Silverlight《模仿电子表》

Study Silverlight《模仿电子表》,第1张

概述注:本文参照了http://www.voidcn.com/article/p-sujuobnh-tq.html 一、Clock.xaml.cs using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.

注:本文参照了http://www.voidcn.com/article/p-sujuobnh-tq.html

一、Clock.xaml.cs

using System;
using System.Collections.Generic;
using System.linq;
using System.Net;
using System.windows;
using System.windows.Controls;
using System.windows.documents;
using System.windows.input;
using System.windows.Media;
using System.windows.Media.Animation;
using System.windows.Shapes;
using System.windows.Threading; //定时器

namespace SilverlightBasic.Clock
{
    public partial class Clock : UserControl
    {
        public Clock()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(enableClock);
        }
        /**
         * 加载执行函数
         */
        private voID enableClock(object sender,RoutedEventArgs e) {
            GetDataTime();//先加载一次
            dispatcherTimer mydispatcherTimer = new dispatcherTimer();
            mydispatcherTimer.Interval = new TimeSpan(0,1,0);
            mydispatcherTimer.Tick += new EventHandler(Timer_Tick);
            mydispatcherTimer.Start();
        }
        /**
         * 定时器执行函数
         */
        private voID Timer_Tick(object sender,EventArgs e) {
            GetDataTime();
        }
        /**
         * 处理XAML上文本更新
         */
        private voID GetDataTime() {
            DateTime dataTime = DateTime.Now;
            this.txtHour.Text = String.Format("{0:d2}",dataTime.Hour);
            this.txtMinute.Text = String.Format("{0:d2}",dataTime.Minute);
            this.txtSecond.Text = String.Format("{0:d2}",dataTime.Second);

            this.txtMonth.Text = String.Format("{0:d2}",dataTime.Month);
            this.txtDay.Text = String.Format("{0:d2}",dataTime.Day);
            this.txtWeek.Text = dataTime.DayOfWeek.ToString().Substring(0,3);
        }
    }
}

二、Clock.xaml

<UserControl x:Class="SilverlightBasic.Clock.Clock"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWIDth="400">
    <Canvas WIDth="180" Height="150" name="Page" Background="#0030628D">
        <Rectangle name="Frame" WIDth="180" Height="150" stroke="#FF000000" strokeThickness="1"
                   RadiusX="20" RadiusY="15">
            <Rectangle.Fill>
                <linearGradIEntBrush EndPoint="0.5,1.1" StartPoint="0.5,-0.1">
                    <GradIEntStop color="#FF259888" Offset="0"/>
                    <GradIEntStop color="#FFC87947" Offset="0.416"/>
                    <GradIEntStop color="#FFC87947" Offset="0.636"/>
                    <GradIEntStop color="#FF259888" Offset="0.981"/>
                </linearGradIEntBrush>
            </Rectangle.Fill>
        </Rectangle>
        <Rectangle name="Panel" WIDth="164" Height="134" Fill="#7F91B52C"
                   stroke="#FFA2AEBF" RadiusX="50" RadiusY="15" Canvas.left="8"
                   Canvas.top="8" strokeThickness="2"/>
        <Path name="line1" WIDth="163" Height="1" Fill="#FF100888" Stretch="Fill"
              stroke="#FF1B510C" Canvas.left="8" Canvas.top="92"
              Data="M33.50029,83.29705 l161.89657,83.297051"/>
        <Path x:name="line2" WIDth="1" Height="49" Fill="#FF100888" Stretch="Fill"
              stroke="#FF1B510C" Canvas.left="63" Canvas.top="92"
              Data="M81.450752,138.29705 L81.450752,90.29705"/>
        <Path x:name="line3" WIDth="1" Height="49" Fill="#FF100888" Stretch="Fill"
              stroke="#FF1B510C" Canvas.left="119" Canvas.top="92"
              Data="M118.30501,164.29698 L118.30501,116.29699"/>
        <!-- M D W -->
        <TextBlock x:name="Month" WIDth="16" Height="19" Canvas.left="32.5"
                   Canvas.top="92" textwrap@R_301_6817@="Wrap" Foreground="#FF100888" Text="M"/>
        <TextBlock WIDth="16" Height="19" Canvas.left="87" Canvas.top="92"
                   textwrap@R_301_6817@="Wrap" x:name="Day" Foreground="#FF100888" Text="D"/>
        <TextBlock WIDth="16" Height="19" Canvas.left="136" Canvas.top="92"
                   textwrap@R_301_6817@="Wrap" x:name="Week" Foreground="#FF100888" Text="W"/>
        <!-- M D W的值 -->
        <TextBlock x:name="txtMonth" WIDth="19" Height="19" Canvas.left="29"
                   Canvas.top="111" textwrap@R_301_6817@="Wrap" Foreground="#FF100888" Text="12"/>
        <TextBlock x:name="txtDay" WIDth="20.5" Height="19" Canvas.left="83.5"
                   Canvas.top="111" textwrap@R_301_6817@="Wrap" Foreground="#FF100888" Text="31"/>
        <TextBlock x:name="txtWeek" WIDth="32.5" Height="19" Canvas.left="130"
                   Canvas.top="111" textwrap@R_301_6817@="Wrap" Foreground="#FF100888" Text="Sun"/>
        <!-- 时间值 -->
        <TextBlock x:name="txtHour" WIDth="48" Height="48" Canvas.left="14.5" Canvas.top="38"
                   textwrap@R_301_6817@="Wrap" FontSize="36" Foreground="#FF100888" Text="23"/>
        <TextBlock x:name="txtMinute" WIDth="48" Height="48" Canvas.left="68.5" Canvas.top="38"
                   textwrap@R_301_6817@="Wrap" FontSize="36" Foreground="#FF100888" Text="59"/>
        <TextBlock x:name="txtSecond" WIDth="49" Height="48" Canvas.left="122" Canvas.top="38"
                   textwrap@R_301_6817@="Wrap" FontSize="36" Foreground="#FF100888" Text="59"/>
        <!-- two : -->
        <TextBlock x:name="Colon1" WIDth="9.5" Height="27" Canvas.left="62.5" Canvas.top="48"
                   textwrap@R_301_6817@="Wrap" Foreground="#FF100888" Text=":" FontSize="20"/>
        <TextBlock x:name="Colon2" WIDth="12" Height="27" Canvas.left="116.5" Canvas.top="48"
                   textwrap@R_301_6817@="Wrap" Foreground="#FF100888" Text=":" FontSize="20"/>
        <!-- copyright -->
        <TextBlock x:name="copyright" WIDth="88" Height="16" Canvas.left="50" textwrap@R_301_6817@="Wrap"
                   FontSize="12" Canvas.top="22" Foreground="#FF100888" Text="@copyright"/>
    </Canvas>
</UserControl>
三、效果图

 

---------------------------------------------------------------------------------------------------------------------------

总结

以上是内存溢出为你收集整理的Study Silverlight《模仿电子表》全部内容,希望文章能够帮你解决Study Silverlight《模仿电子表》所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1064066.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存