微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Silverlight 版的电子表

程序执行的效果图:

image

这个程序改编自:webabcd 的 Silverlight 1.0 同样程序。

http://www.cnblogs.com/webabcd/archive/2007/09/17/895328.html 

我这里把 Silverlight 1.0 的程序改成 Silverlight 3.0 的程序了。中间的逻辑,原先是JavaScript写的,现在变成C#写的了。

程序是用VS2010 beta 写的, 使用的是 VS2010 认创建的 Silverlight 项目来编写的。 对其中改动的部分代码如下:

MainPage.xaml 文件

<UserControl x:Class="ClockSilverlightApp.MainPage"
    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" Loaded="UserControl_Loaded">

    <Canvas
	xmlns="http://schemas.microsoft.com/client/2007"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	Width="180" Height="150"
	Background="#0030628D"
	x:Name="Page" >
        <Rectangle x: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="#FF259888" Offset="0.981"/>
                    <GradientStop Color="#FFC87947" Offset="0.416"/>
                    <GradientStop Color="#FFC87947" Offset="0.636"/>
                
  
  LinearGradientBrush>
             
   Rectangle.Fill>  
    Rectangle> <Rectangle x:Name="Panel" Width="164" Height="134" Fill="#7F91B52C" stroke="#FFA2AEBF" RadiusX="50" RadiusY="15" Canvas.Left="8" Canvas.Top="8" strokeThickness="2"/> <Path x: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="56" 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="110" Canvas.Top="92" Data="M118.30501,164.29698 L118.30501,116.29699"/> <TextBlock x:Name="Month" Width="16" Height="19" Canvas.Left="30" Canvas.Top="92" textwrapping="Wrap" Foreground="#FF100888" Text="月"/> <TextBlock Width="16" Height="19" Canvas.Left="78" Canvas.Top="92" textwrapping="Wrap" x:Name="Day" Foreground="#FF100888" Text="日"/> <TextBlock Width="30" Height="19" Canvas.Left="129" Canvas.Top="92" textwrapping="Wrap" x:Name="Week" Foreground="#FF100888" Text="星期"/> <TextBlock x:Name="txtMonth" Width="19" Height="19" Canvas.Left="28" Canvas.Top="111" textwrapping="Wrap" Foreground="#FF100888" Text="12"/> <TextBlock x:Name="txtDay" Width="20.5" Height="19" Canvas.Left="77" Canvas.Top="111" textwrapping="Wrap" Foreground="#FF100888" Text="31"/> <TextBlock x:Name="txtWeek" Width="20" Height="19" Canvas.Left="133" Canvas.Top="111" textwrapping="Wrap" Foreground="#FF100888" Text="六"/> <TextBlock x:Name="txtHour" Width="48" Height="48" Canvas.Left="14.5" Canvas.Top="38" textwrapping="Wrap" FontSize="36" Foreground="#FF100888" Text="23"/> <TextBlock x:Name="txtMinute" Width="48" Height="48" Canvas.Left="68.5" Canvas.Top="38" textwrapping="Wrap" FontSize="36" Foreground="#FF100888" Text="59"/> <TextBlock x:Name="txtSecond" Width="49" Height="48" Canvas.Left="122" Canvas.Top="38" textwrapping="Wrap" FontSize="36" Foreground="#FF100888" Text="59"/> <TextBlock x:Name="Colon1" Width="9.5" Height="27" Canvas.Left="62.5" Canvas.Top="48" textwrapping="Wrap" Foreground="#FF100888" Text=":" FontSize="20"/> <TextBlock x:Name="Colon2" Width="12" Height="27" Canvas.Left="116.5" Canvas.Top="48" textwrapping="Wrap" Foreground="#FF100888" Text=":" FontSize="20"/> <TextBlock x:Name="copyright" Width="88" Height="16" Canvas.Left="16" textwrapping="Wrap" FontSize="12" Canvas.Top="22" Foreground="#FF100888" Text="郭红俊 clock" MouseLeftButtonDown="copyright_MouseLeftButtonDown" MouseEnter="TextBlock_MouseEnter" MouseLeave="TextBlock_MouseLeave" /> <TextBlock x:Name="FullScreen" Width="88" Height="16" Canvas.Left="106" textwrapping="Wrap" FontSize="12" Canvas.Top="22" Foreground="#FF100888" Text="FullScreen" MouseEnter="TextBlock_MouseEnter" MouseLeave="TextBlock_MouseLeave" MouseLeftButtonDown="FullScreen_MouseLeftButtonDown" />  
     Canvas>  
      UserControl>

MainPage.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;
using System.Windows.browser;

namespace ClockSilverlightApp
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            dicWeek.Add(DayOfWeek.Friday,"");
            dicWeek.Add(DayOfWeek.Monday,"");
            dicWeek.Add(DayOfWeek.Saturday,"六");
            dicWeek.Add(DayOfWeek.Sunday,"");
            dicWeek.Add(DayOfWeek.Thursday,"");
            dicWeek.Add(DayOfWeek.Tuesday,"");
            dicWeek.Add(DayOfWeek.Wednesday,"");

        }

        private static readonly Dictionary
 
 
  
  string> dicWeek = 
  
  new Dictionary
  
  
    string>(); 
   /// /// 定时更新前段显示信息事件 ///  
   ///  
   ///  
   private 
   void enableClock( 
   object sender,EventArgs e) { DateTime dt = DateTime.Now; 
   this.txtMonth.Text = 
   string.Format(" 
   {0:00}",dt.Month); 
   this.txtDay.Text = 
   string.Format(" 
   {0:00}",dt.Day); 
   this.txtWeek.Text = dicWeek[dt.DayOfWeek]; 
   this.txtHour.Text = 
   string.Format(" 
   {0:00}",dt.Hour); 
   this.txtMinute.Text = 
   string.Format(" 
   {0:00}",dt.Minute); 
   this.txtSecond.Text = 
   string.Format(" 
   {0:00}",dt.Second); } dispatcherTimer timer = 
   new dispatcherTimer(); 
   private 
   void UserControl_Loaded( 
   object sender,RoutedEventArgs e) { enableClock( 
   null,null); timer.Interval = 
   new TimeSpan(0,1); timer.Tick += 
   new EventHandler(enableClock); timer.Start(); } 
   private 
   void copyright_MouseLeftButtonDown( 
   object sender,MouseButtonEventArgs e) { HtmlPage.Window.Navigate( 
   new Uri(" 
   http://www.csdn.net/")," 
   new"); } 
   private 
   void TextBlock_MouseEnter( 
   object sender,MouseEventArgs e) { 
   if (sender == 
   null) 
   return; TextBlock tb = sender 
   as TextBlock; 
   if (tb == 
   null) 
   return; 
   // TextBlock.foreground tb.Foreground = 
   new SolidColorBrush(Colors.Red); 
   // TextBlock.textdecorations tb.Textdecorations = Textdecorations.Underline; tb.Cursor = Cursors.Hand; } 
   private 
   void TextBlock_MouseLeave( 
   object sender,MouseEventArgs e) { 
   if (sender == 
   null) 
   return; TextBlock tb = sender 
   as TextBlock; 
   if (tb == 
   null) 
   return; 
   // TextBlock.foreground tb.Foreground = 
   new SolidColorBrush(Color.FromArgb(255,16,8,136)); 
   // TextBlock.textdecorations tb.Textdecorations = 
   null; tb.Cursor = Cursors.Arrow; } 
   private 
   void FullScreen_MouseLeftButtonDown( 
   object sender,MouseButtonEventArgs e) { Application.Current.Host.Content.IsFullScreen = !Application.Current.Host.Content.IsFullScreen; } } } 
  ,>
 
 ,>

其他文件没有变化。

这个程序我觉得挺适合初学者做出第一个有点意思的Silverlight程序。所以就把它改写成Silverlight 3 的程序了。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐